Skip to content

Commit

Permalink
feat(testing): prompt e2eTestRunner playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Jul 27, 2023
1 parent 5993a7b commit 6f542f1
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 10 deletions.
8 changes: 8 additions & 0 deletions docs/generated/cli/create-nx-workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ Type: `boolean`

Generate a Dockerfile for the Node API

### e2eTestRunner

Type: `string`

Choices: [cypress, playwright, none]

Test runner to use for end to end (E2E) tests.

### framework

Type: `string`
Expand Down
8 changes: 8 additions & 0 deletions docs/generated/packages/nx/documents/create-nx-workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ Type: `boolean`

Generate a Dockerfile for the Node API

### e2eTestRunner

Type: `string`

Choices: [cypress, playwright, none]

Test runner to use for end to end (E2E) tests.

### framework

Type: `string`
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/workspace/generators/new.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"e2eTestRunner": {
"description": "The tool to use for running e2e tests.",
"type": "string",
"enum": ["cypress", "jest", "detox", "none"]
"enum": ["cypress", "playwright", "jest", "detox", "none"]
}
},
"additionalProperties": true,
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/workspace/generators/preset.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"e2eTestRunner": {
"description": "The tool to use for running e2e tests.",
"type": "string",
"enum": ["cypress", "jest", "detox", "none"]
"enum": ["cypress", "playwright", "jest", "detox", "none"]
}
},
"required": ["preset", "name"],
Expand Down
1 change: 1 addition & 0 deletions e2e/storybook/src/storybook-nested.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('Storybook generators and executors for standalone workspaces - using R
style: 'css',
bundler: 'vite',
packageManager: getSelectedPackageManager(),
e2eTestRunner: 'none',
});

runCLI(
Expand Down
6 changes: 6 additions & 0 deletions e2e/utils/create-project-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export function runCreateWorkspace(
standaloneApi,
docker,
nextAppDir,
e2eTestRunner,
}: {
preset: string;
appName?: string;
Expand All @@ -153,6 +154,7 @@ export function runCreateWorkspace(
routing?: boolean;
docker?: boolean;
nextAppDir?: boolean;
e2eTestRunner?: 'cypress' | 'playwright' | 'jest' | 'detox' | 'none';
}
) {
projName = name;
Expand Down Expand Up @@ -198,6 +200,10 @@ export function runCreateWorkspace(
command += ` --package-manager=${packageManager}`;
}

if (e2eTestRunner) {
command += ` --e2eTestRunner=${e2eTestRunner}`;
}

if (extraArgs) {
command += ` ${extraArgs}`;
}
Expand Down
13 changes: 12 additions & 1 deletion e2e/workspace-create/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('create-nx-workspace', () => {
packageManager,
standaloneApi: false,
routing: false,
e2eTestRunner: 'none',
});

checkFilesExist('package.json');
Expand All @@ -50,6 +51,7 @@ describe('create-nx-workspace', () => {
packageManager,
standaloneApi: true,
routing: true,
e2eTestRunner: 'none',
});

checkFilesExist('package.json');
Expand All @@ -68,6 +70,7 @@ describe('create-nx-workspace', () => {
style: 'css',
packageManager,
bundler: 'vite',
e2eTestRunner: 'none',
});

checkFilesExist('package.json');
Expand All @@ -77,7 +80,7 @@ describe('create-nx-workspace', () => {
expectCodeIsFormatted();
});

it('should create a workspace with a single react app with webpack at the root', () => {
it('should create a workspace with a single react app with webpack and playwright at the root', () => {
const wsName = uniq('react');

runCreateWorkspace(wsName, {
Expand All @@ -86,6 +89,7 @@ describe('create-nx-workspace', () => {
style: 'css',
packageManager,
bundler: 'webpack',
e2eTestRunner: 'playwright',
});

checkFilesExist('package.json');
Expand Down Expand Up @@ -144,6 +148,7 @@ describe('create-nx-workspace', () => {
packageManager,
standaloneApi: false,
routing: true,
e2eTestRunner: 'none',
});
expectCodeIsFormatted();
});
Expand All @@ -162,6 +167,7 @@ describe('create-nx-workspace', () => {
packageManager,
standaloneApi: false,
routing: false,
e2eTestRunner: 'none',
})
).toThrow();
});
Expand All @@ -176,6 +182,7 @@ describe('create-nx-workspace', () => {
appName,
packageManager,
bundler: 'webpack',
e2eTestRunner: 'none',
});

expectNoAngularDevkit();
Expand All @@ -195,6 +202,7 @@ describe('create-nx-workspace', () => {
appName,
packageManager,
bundler: 'vite',
e2eTestRunner: 'none',
});

expectNoAngularDevkit();
Expand All @@ -213,6 +221,7 @@ describe('create-nx-workspace', () => {
appName,
nextAppDir: false,
packageManager,
e2eTestRunner: 'none',
});

checkFilesExist(`apps/${appName}/pages/index.tsx`);
Expand All @@ -230,6 +239,7 @@ describe('create-nx-workspace', () => {
nextAppDir: true,
appName,
packageManager,
e2eTestRunner: 'none',
});

checkFilesExist('app/page.tsx');
Expand All @@ -247,6 +257,7 @@ describe('create-nx-workspace', () => {
nextAppDir: false,
appName,
packageManager,
e2eTestRunner: 'none',
});

checkFilesExist('pages/index.tsx');
Expand Down
49 changes: 47 additions & 2 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface ReactArguments extends BaseArguments {
style: string;
bundler: 'webpack' | 'vite' | 'rspack';
nextAppDir: boolean;
e2eTestRunner: 'none' | 'cypress' | 'playwright';
}

interface AngularArguments extends BaseArguments {
Expand All @@ -58,6 +59,7 @@ interface AngularArguments extends BaseArguments {
style: string;
routing: boolean;
standaloneApi: boolean;
e2eTestRunner: 'none' | 'cypress' | 'playwright';
}

interface NodeArguments extends BaseArguments {
Expand Down Expand Up @@ -147,6 +149,11 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
.option('nextAppDir', {
describe: chalk.dim`Enable the App Router for Next.js`,
type: 'boolean',
})
.option('e2eTestRunner', {
describe: chalk.dim`Test runner to use for end to end (E2E) tests.`,
choices: ['cypress', 'playwright', 'none'],
type: 'string',
}),
withNxCloud,
withCI,
Expand Down Expand Up @@ -448,6 +455,7 @@ async function determineReactOptions(
let style: undefined | string = undefined;
let appName: string;
let bundler: undefined | 'webpack' | 'vite' | 'rspack' = undefined;
let e2eTestRunner: undefined | 'none' | 'cypress' | 'playwright' = undefined;
let nextAppDir = false;

if (parsedArgs.preset && parsedArgs.preset !== Preset.React) {
Expand Down Expand Up @@ -497,8 +505,10 @@ async function determineReactOptions(

if (preset === Preset.ReactStandalone || preset === Preset.ReactMonorepo) {
bundler = await determineReactBundler(parsedArgs);
e2eTestRunner = await determineE2eTestRunner(parsedArgs);
} else if (preset === Preset.NextJs || preset === Preset.NextJsStandalone) {
nextAppDir = await determineNextAppDir(parsedArgs);
e2eTestRunner = await determineE2eTestRunner(parsedArgs);
}

if (parsedArgs.style) {
Expand Down Expand Up @@ -549,7 +559,7 @@ async function determineReactOptions(
style = reply.style;
}

return { preset, style, appName, bundler, nextAppDir };
return { preset, style, appName, bundler, nextAppDir, e2eTestRunner };
}

async function determineAngularOptions(
Expand All @@ -559,6 +569,7 @@ async function determineAngularOptions(
let style: string;
let appName: string;
let standaloneApi: boolean;
let e2eTestRunner: undefined | 'none' | 'cypress' | 'playwright' = undefined;
let routing: boolean;

if (parsedArgs.preset && parsedArgs.preset !== Preset.Angular) {
Expand Down Expand Up @@ -609,6 +620,8 @@ async function determineAngularOptions(
style = reply.style;
}

e2eTestRunner = await determineE2eTestRunner(parsedArgs);

if (parsedArgs.standaloneApi !== undefined) {
standaloneApi = parsedArgs.standaloneApi;
} else {
Expand Down Expand Up @@ -655,7 +668,7 @@ async function determineAngularOptions(
routing = reply.routing === 'Yes';
}

return { preset, style, appName, standaloneApi, routing };
return { preset, style, appName, standaloneApi, routing, e2eTestRunner };
}

async function determineNodeOptions(
Expand Down Expand Up @@ -950,3 +963,35 @@ async function determineNodeFramework(
]);
return reply.framework;
}

async function determineE2eTestRunner(
parsedArgs: yargs.Arguments<{
e2eTestRunner?: 'none' | 'cypress' | 'playwright';
}>
): Promise<'none' | 'cypress' | 'playwright'> {
if (parsedArgs.e2eTestRunner) return parsedArgs.e2eTestRunner;
const reply = await enquirer.prompt<{
e2eTestRunner: 'none' | 'cypress' | 'playwright';
}>([
{
message: 'Test runner to use for end to end (E2E) tests',
type: 'autocomplete',
name: 'e2eTestRunner',
choices: [
{
name: 'cypress',
message: 'Cypress [ https://www.cypress.io/ ]',
},
{
name: 'playwright',
message: 'Playwright [ https://playwright.dev/ ]',
},
{
name: 'none',
message: 'None',
},
],
},
]);
return reply.e2eTestRunner;
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function createTempWorkspace(options: NormalizedOptions) {
options.isVite ? 'vite' : 'webpack'
} --packageManager=${options.packageManager} ${
options.nxCloud ? '--nxCloud' : '--nxCloud=false'
}`,
} ${options.addE2e ? '--e2eTestRunner=cypress' : '--e2eTestRunner=none'}`,
{ stdio: [0, 1, 2] }
);

Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/src/generators/new/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface Schema {
standaloneApi?: boolean;
routing?: boolean;
packageManager?: PackageManager;
e2eTestRunner?: 'cypress' | 'detox' | 'jest' | 'none';
e2eTestRunner?: 'cypress' | 'playwright' | 'detox' | 'jest' | 'none';
}

export interface NormalizedSchema extends Schema {
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/src/generators/new/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"e2eTestRunner": {
"description": "The tool to use for running e2e tests.",
"type": "string",
"enum": ["cypress", "jest", "detox", "none"]
"enum": ["cypress", "playwright", "jest", "detox", "none"]
}
},
"additionalProperties": true
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/src/generators/preset/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export interface Schema {
nextAppDir?: boolean;
routing?: boolean;
standaloneApi?: boolean;
e2eTestRunner?: 'cypress' | 'jest' | 'detox' | 'none';
e2eTestRunner?: 'cypress' | 'playwright' | 'jest' | 'detox' | 'none';
js?: boolean;
}
2 changes: 1 addition & 1 deletion packages/workspace/src/generators/preset/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"e2eTestRunner": {
"description": "The tool to use for running e2e tests.",
"type": "string",
"enum": ["cypress", "jest", "detox", "none"]
"enum": ["cypress", "playwright", "jest", "detox", "none"]
}
},
"required": ["preset", "name"]
Expand Down

0 comments on commit 6f542f1

Please sign in to comment.