nx/e2e/react/src/playwright.test.ts
Jack Hsu 27edf71cef
feat(misc): make directory a required option for generators (#28093)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

---------

Co-authored-by: Colum Ferry <cferry09@gmail.com>
Co-authored-by: Nicholas Cunningham <ndcunningham@gmail.com>
2024-10-01 09:29:44 -04:00

64 lines
1.6 KiB
TypeScript

import {
runCLI,
runE2ETests,
cleanupProject,
newProject,
uniq,
updateFile,
} from '@nx/e2e/utils';
describe('React Playwright e2e tests', () => {
let projectName;
const appName = uniq('pw-react-app');
const usedInAppLibName = uniq('pw-react-lib');
beforeAll(async () => {
projectName = newProject({
name: uniq('pw-react'),
packages: ['@nx/react'],
});
runCLI(
`generate @nx/react:app ${appName} --e2eTestRunner=playwright --bundler=vite --no-interactive`
);
});
afterAll(() => cleanupProject());
it('should execute e2e tests using playwright', () => {
if (runE2ETests()) {
const result = runCLI(`e2e ${appName}-e2e --verbose`);
expect(result).toContain(
`Successfully ran target e2e for project ${appName}-e2e`
);
}
});
it('should execute e2e tests using playwright with a library used in the app', () => {
runCLI(
`generate @nx/js:library ${usedInAppLibName} --unitTestRunner=none --importPath=@mylib --no-interactive`
);
updateFile(
`${appName}-e2e/src/example.spec.ts`,
`
import { test, expect } from '@playwright/test';
import * as mylib from '@mylib'
test('has title', async ({ page }) => {
await page.goto('/');
// Expect h1 to contain a substring.
expect(await page.locator('h1').innerText()).toContain('Welcome');
});
`
);
if (runE2ETests()) {
const result = runCLI(`e2e ${appName}-e2e --verbose`);
expect(result).toContain(
`Successfully ran target e2e for project ${appName}-e2e`
);
}
});
});