-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nextjs): Playwright should work with workspace libs (#20933)
- Loading branch information
1 parent
d1a2d45
commit f1849a7
Showing
3 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
runCLI, | ||
runE2ETests, | ||
cleanupProject, | ||
newProject, | ||
uniq, | ||
updateFile, | ||
} from '@nx/e2e/utils'; | ||
|
||
describe('Next Playwright e2e tests', () => { | ||
let projectName; | ||
const appName = uniq('pw-next-app'); | ||
const usedInAppLibName = uniq('pw-next-lib'); | ||
|
||
beforeAll(async () => { | ||
projectName = newProject({ | ||
name: uniq('pw-next'), | ||
packages: ['@nx/next'], | ||
}); | ||
runCLI( | ||
`generate @nx/next:app ${appName} --e2eTestRunner=playwright --projectNameAndRootFormat=as-provided --no-interactive` | ||
); | ||
}); | ||
|
||
afterAll(() => cleanupProject()); | ||
|
||
it('should execute e2e tests using playwright', () => { | ||
if (runE2ETests()) { | ||
const result = runCLI(`e2e ${appName}-e2e --no-watch --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 --projectNameAndRootFormat=as-provided --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 --no-watch --verbose`); | ||
expect(result).toContain( | ||
`Successfully ran target e2e for project ${appName}-e2e` | ||
); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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 --projectNameAndRootFormat=as-provided --no-interactive` | ||
); | ||
}); | ||
|
||
afterAll(() => cleanupProject()); | ||
|
||
it('should execute e2e tests using playwright', () => { | ||
if (runE2ETests()) { | ||
const result = runCLI(`e2e ${appName}-e2e --no-watch --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 --projectNameAndRootFormat=as-provided --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 --no-watch --verbose`); | ||
expect(result).toContain( | ||
`Successfully ran target e2e for project ${appName}-e2e` | ||
); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters