Skip to content

Commit

Permalink
fix(task): consider config sys in task runner
Browse files Browse the repository at this point in the history
this commit updates the generation of a `ValidatedConfig` entity to take
a `sys` property on a user provided `Config` in the context of
`runTask`.

when generating the validated configuration, the `sys` entity takes
precedence over all other configurations, with the belief that in the
event argument was provided, it is the intent of the user to use it. in
the event `sys` is not expressly provided, use the one on the provided
configuration entity. this is useful in the case that a user used
stencil's external facing apis in a flow that:
1. loads a configuration
2. validates that configuration
3. uses that configuration when calling `runTask` directly

this commit fixes a bug introduced making `sys` a required field on
`ValidatedConfig`, where `config.sys` was not properly accounted for.
the bug was initially introduced in
a6a9171 (#3491)
  • Loading branch information
rwaskiewicz committed Aug 11, 2022
1 parent 8d2cbea commit 3dd628a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const runTask = async (
flags: createConfigFlags(config.flags ?? { task }),
logger,
outputTargets: config.outputTargets ?? [],
sys: sys ?? coreCompiler.createSystem({ logger }),
sys: sys ?? config.sys ?? coreCompiler.createSystem({ logger }),
testing: config.testing ?? {},
};

Expand Down
23 changes: 23 additions & 0 deletions src/cli/test/run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,29 @@ describe('run', () => {
taskTestSpy.mockRestore();
});

describe('default configuration', () => {
describe('sys property', () => {
it('uses the sys argument if one is provided', async () => {
// default to the optional `sys` argument first
validatedConfig = mockValidatedConfig({ sys });

await runTask(coreCompiler, unvalidatedConfig, 'build', sys);

expect(taskBuildSpy).toHaveBeenCalledWith(coreCompiler, validatedConfig);
});


it('uses the sys field on the config if no sys argument is provided', async () => {
// if the optional `sys` argument isn't provided, attempt to default to the one on the config
expect(unvalidatedConfig.sys).toBeTruthy();

await runTask(coreCompiler, unvalidatedConfig, 'build');

expect(taskBuildSpy).toHaveBeenCalledWith(coreCompiler, validatedConfig);
});
});
});

it('calls the build task', async () => {
await runTask(coreCompiler, unvalidatedConfig, 'build', sys);

Expand Down

0 comments on commit 3dd628a

Please sign in to comment.