Skip to content

Commit

Permalink
fix(task): consider config sys in task runner (ionic-team#3518)
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 (ionic-team#3491)
  • Loading branch information
rwaskiewicz committed Aug 15, 2022
1 parent 8d2cbea commit 103ec60
Show file tree
Hide file tree
Showing 2 changed files with 33 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
32 changes: 32 additions & 0 deletions src/cli/test/run.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,38 @@ describe('run', () => {
taskTestSpy.mockRestore();
});

describe('default configuration', () => {
describe('sys property', () => {
it('uses the sys argument if one is provided', async () => {
// remove the `CompilerSystem` on the config, just to be sure we don't accidentally use it
unvalidatedConfig.sys = undefined;

validatedConfig = mockValidatedConfig({ sys });

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

// first validate there was one call, and that call had two arguments
expect(taskBuildSpy).toHaveBeenCalledTimes(1);
expect(taskBuildSpy).toHaveBeenCalledWith(coreCompiler, validatedConfig);

const compilerSystemUsed: d.CompilerSystem = taskBuildSpy.mock.calls[0][1].sys;
expect(compilerSystemUsed).toBe(sys);
});

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
await runTask(coreCompiler, unvalidatedConfig, 'build');

// first validate there was one call, and that call had two arguments
expect(taskBuildSpy).toHaveBeenCalledTimes(1);
expect(taskBuildSpy).toHaveBeenCalledWith(coreCompiler, validatedConfig);

const compilerSystemUsed: d.CompilerSystem = taskBuildSpy.mock.calls[0][1].sys;
expect(compilerSystemUsed).toBe(unvalidatedConfig.sys);
});
});
});

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

Expand Down

0 comments on commit 103ec60

Please sign in to comment.