Skip to content

Commit

Permalink
fix inheritTasks with taskPrefix (#1525)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Jun 17, 2024
1 parent e5f7908 commit 89c2f99
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
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']);
});
});
});

0 comments on commit 89c2f99

Please sign in to comment.