fix(core): support target without watch option (#2735)
This commit checks if the target dev server supports the watch option before forwarding it to, this is relevant for running Cypress against dev server target that does not support this option, for instance "@nguniversal/builders:ssr-dev-server".
This commit is contained in:
parent
f4ea0df51d
commit
5340986722
@ -29,6 +29,9 @@ describe('Cypress builder', () => {
|
||||
ReturnType<typeof installedCypressVersion>
|
||||
> = installedCypressVersion as any;
|
||||
mockContext = { root: '/root', workspace: { projects: {} } } as any;
|
||||
(devkit as any).readTargetOptions = jest.fn().mockReturnValue({
|
||||
watch: true,
|
||||
});
|
||||
let runExecutor: any;
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -285,4 +288,38 @@ describe('Cypress builder', () => {
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should not forward watch option to devServerTarget when not supported', async () => {
|
||||
// Simulate a dev server target that does not support watch option.
|
||||
(devkit as any).readTargetOptions = jest.fn().mockReturnValue({});
|
||||
|
||||
const { success } = await cypressExecutor(cypressOptions, mockContext);
|
||||
|
||||
expect(success).toEqual(true);
|
||||
expect((devkit as any).readTargetOptions.mock.calls[0][0]).toEqual(
|
||||
expect.objectContaining({
|
||||
project: 'my-app',
|
||||
target: 'serve',
|
||||
})
|
||||
);
|
||||
expect(Object.keys(runExecutor.mock.calls[0][1])).not.toContain('watch');
|
||||
});
|
||||
|
||||
it('should forward watch option to devServerTarget when supported', async () => {
|
||||
// Simulate a dev server target that support watch option.
|
||||
(devkit as any).readTargetOptions = jest
|
||||
.fn()
|
||||
.mockReturnValue({ watch: true });
|
||||
|
||||
const { success } = await cypressExecutor(cypressOptions, mockContext);
|
||||
|
||||
expect(success).toEqual(true);
|
||||
expect((devkit as any).readTargetOptions.mock.calls[0][0]).toEqual(
|
||||
expect.objectContaining({
|
||||
project: 'my-app',
|
||||
target: 'serve',
|
||||
})
|
||||
);
|
||||
expect(Object.keys(runExecutor.mock.calls[0][1])).toContain('watch');
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,6 +4,7 @@ import {
|
||||
ExecutorContext,
|
||||
logger,
|
||||
parseTargetString,
|
||||
readTargetOptions,
|
||||
runExecutor,
|
||||
stripIndents,
|
||||
} from '@nrwl/devkit';
|
||||
@ -115,14 +116,23 @@ async function* startDevServer(
|
||||
const { project, target, configuration } = parseTargetString(
|
||||
opts.devServerTarget
|
||||
);
|
||||
const devServerTargetOpts = readTargetOptions(
|
||||
{ project, target, configuration },
|
||||
context
|
||||
);
|
||||
const targetSupportsWatchOpt = Object.keys(devServerTargetOpts).includes(
|
||||
'watch'
|
||||
);
|
||||
|
||||
for await (const output of await runExecutor<{
|
||||
success: boolean;
|
||||
baseUrl?: string;
|
||||
}>(
|
||||
{ project, target, configuration },
|
||||
{
|
||||
watch: opts.watch,
|
||||
},
|
||||
// @NOTE: Do not forward watch option if not supported by the target dev server,
|
||||
// this is relevant for running Cypress against dev server target that does not support this option,
|
||||
// for instance @nguniversal/builders:ssr-dev-server.
|
||||
targetSupportsWatchOpt ? { watch: opts.watch } : {},
|
||||
context
|
||||
)) {
|
||||
if (!output.success && !opts.watch)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user