Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix inheritTasks with taskPrefix #1525

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/actions/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ export abstract class TasksMixin {
currentPrototype = Object.getPrototypeOf(currentPrototype);
}

propertyDescriptors = propertyDescriptors.filter(([name]) => queueNames.includes(name));
const { taskPrefix = '' } = this.features;
propertyDescriptors = propertyDescriptors.filter(
([name]) => name.startsWith(taskPrefix) && queueNames.includes(name.slice(taskPrefix.length)),
);
return Object.fromEntries(propertyDescriptors);
}

Expand Down
35 changes: 35 additions & 0 deletions test/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1966,5 +1966,40 @@ describe('Base', () => {
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(gen), 'default')!.value,
);
});

it('passing taskPrefix should return tasks without taskPrefix', async function () {
const Gen = class extends TestGen {
constructor(args, options, features) {
super(args, options, { ...features, taskPrefix: 'foo' });
}

foodefault() {}

foobar() {}
};

const gen = new Gen([], { env });
assert.deepStrictEqual(gen.getTaskNames(), ['default', 'bar']);
});

it('passing taskPrefix and inheritTasks should return tasks without taskPrefix', async function () {
const Parent = class extends TestGen {
constructor(args, options, features) {
super(args, options, { ...features, taskPrefix: 'foo', inheritTasks: true });
}

foodefault() {}
};
const Gen = class extends Parent {
constructor(args, options, features) {
super(args, options, { ...features, taskPrefix: 'foo', inheritTasks: true });
}

fooinitializing() {}
};

const gen = new Gen([], { env });
assert.deepStrictEqual(gen.getTaskNames(), ['default', 'initializing']);
});
});
});
Loading