Skip to content

Commit

Permalink
fix(testing): make the default react playwright test to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Aug 10, 2023
1 parent 0527925 commit b920ba0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
15 changes: 13 additions & 2 deletions packages/playwright/src/executors/playwright/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,21 @@ export async function playwrightExecutor(

const args = createArgs(options);
const p = runPlaywright(args, context.root);
p.stdout.on('data', (message) => {
process.stdout.write(message);
});
p.stderr.on('data', (message) => {
process.stderr.write(message);
});

return new Promise<{ success: boolean }>((resolve) => {
p.on('close', (code) => {
resolve({ success: code === 0 });
if (code !== 0) {
console.error(`Playwright exited with code ${code}`);
resolve({ success: false });
} else {
resolve({ success: true });
}
});
});
}
Expand Down Expand Up @@ -117,7 +128,7 @@ function runPlaywright(args: string[], cwd: string) {
const cli = require.resolve('@playwright/test/cli');

return fork(cli, ['test', ...args], {
stdio: 'inherit',
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
cwd,
});
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Rename or remove the existing e2e target.`);
projectConfig.targets ??= {};
projectConfig.targets.e2e = {
executor: '@nx/playwright:playwright',
outputs: [`dist/.playwright/${projectConfig.root}`],
outputs: [`{workspaceRoot}/dist/.playwright/${projectConfig.root}`],
options: {
config: `${projectConfig.root}/playwright.config.${
options.js ? 'js' : 'ts'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ test('has title', async ({ page }) => {
await page.goto('/');

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Welcome/);
await expect(page).toHaveTitle(/<%= project %>/);
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const baseURL = process.env['BASE_URL'] || '<% if(webServerAddress) {%><%= webSe
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
...nxE2EPreset(__filename, { testDir: './<>' }),
...nxE2EPreset(__filename, { testDir: './src' }),
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL,
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/generators/application/lib/add-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export async function addE2e(
webServerCommand: `${getPackageManagerCommand().exec} nx serve ${
options.name
}`,
webServerAddress: 'localhost:4200',
});
case 'none':
default:
Expand Down

0 comments on commit b920ba0

Please sign in to comment.