-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(testing): ensure baseUrl is not passed to playwright cli
- Loading branch information
Showing
4 changed files
with
186 additions
and
0 deletions.
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
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
113 changes: 113 additions & 0 deletions
113
packages/playwright/src/migrations/update-18-1-0/remove-baseUrl-from-project-json.spec.ts
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,113 @@ | ||
import { addProjectConfiguration, readProjectConfiguration } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import removeBaseUrlFromProjectJson from './remove-baseUrl-from-project-json'; | ||
|
||
describe('removeBaseUrlFromProjectJson', () => { | ||
it('should not update if the project is correct', async () => { | ||
// ARRANGE | ||
const tree = createTreeWithEmptyWorkspace(); | ||
const project = { | ||
$schema: 'node_modules/nx/schemas/project-schema.json', | ||
name: 'test', | ||
root: '.', | ||
sourceRoot: '', | ||
targets: { | ||
e2e: { | ||
executor: '@nx/playwright:playwright', | ||
}, | ||
}, | ||
}; | ||
|
||
addProjectConfiguration(tree, 'test', project); | ||
tree.write('playwright.config.ts', ''); | ||
|
||
// ACT | ||
await removeBaseUrlFromProjectJson(tree); | ||
|
||
// ASSERT | ||
const maybeUpdatedProject = readProjectConfiguration(tree, 'test'); | ||
expect(maybeUpdatedProject).toMatchInlineSnapshot(` | ||
{ | ||
"$schema": "node_modules/nx/schemas/project-schema.json", | ||
"name": "test", | ||
"root": ".", | ||
"sourceRoot": "", | ||
"targets": { | ||
"e2e": { | ||
"executor": "@nx/playwright:playwright", | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
it('should remove baseUrl from target options', async () => { | ||
// ARRANGE | ||
const tree = createTreeWithEmptyWorkspace(); | ||
const project = { | ||
$schema: 'node_modules/nx/schemas/project-schema.json', | ||
name: 'test', | ||
root: '.', | ||
sourceRoot: '', | ||
targets: { | ||
e2e: { | ||
executor: '@nx/playwright:playwright', | ||
options: { | ||
baseUrl: 'http://localhost:4200', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
addProjectConfiguration(tree, 'test', project); | ||
tree.write('playwright.config.ts', ''); | ||
|
||
// ACT | ||
await removeBaseUrlFromProjectJson(tree); | ||
|
||
// ASSERT | ||
const maybeUpdatedProject = readProjectConfiguration(tree, 'test'); | ||
expect(maybeUpdatedProject.targets['e2e'].options).toMatchInlineSnapshot( | ||
`{}` | ||
); | ||
}); | ||
|
||
it('should remove baseUrl from target options and configurations', async () => { | ||
// ARRANGE | ||
const tree = createTreeWithEmptyWorkspace(); | ||
const project = { | ||
$schema: 'node_modules/nx/schemas/project-schema.json', | ||
name: 'test', | ||
root: '.', | ||
sourceRoot: '', | ||
targets: { | ||
e2e: { | ||
executor: '@nx/playwright:playwright', | ||
options: { | ||
baseUrl: 'http://localhost:4200', | ||
}, | ||
configurations: { | ||
production: { | ||
baseUrl: 'https://mytest.com', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
addProjectConfiguration(tree, 'test', project); | ||
tree.write('playwright.config.ts', ''); | ||
|
||
// ACT | ||
await removeBaseUrlFromProjectJson(tree); | ||
|
||
// ASSERT | ||
const maybeUpdatedProject = readProjectConfiguration(tree, 'test'); | ||
expect(maybeUpdatedProject.targets['e2e'].options).toMatchInlineSnapshot( | ||
`{}` | ||
); | ||
expect( | ||
maybeUpdatedProject.targets['e2e'].configurations['production'] | ||
).toMatchInlineSnapshot(`{}`); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
packages/playwright/src/migrations/update-18-1-0/remove-baseUrl-from-project-json.ts
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,56 @@ | ||
import { | ||
formatFiles, | ||
getProjects, | ||
joinPathFragments, | ||
type ProjectConfiguration, | ||
type Tree, | ||
updateProjectConfiguration, | ||
} from '@nx/devkit'; | ||
|
||
export default async function (tree: Tree) { | ||
const playwrightProjects: ProjectConfiguration[] = []; | ||
const projects = getProjects(tree); | ||
projects.forEach((project) => { | ||
// Check if the project contains playwright config | ||
const configPath = joinPathFragments(project.root, 'playwright.config.ts'); | ||
if (tree.exists(configPath)) { | ||
playwrightProjects.push(project); | ||
} | ||
}); | ||
|
||
for (const project of playwrightProjects) { | ||
for (const [targetName, target] of Object.entries(project.targets)) { | ||
if (target.executor !== '@nx/playwright:playwright') { | ||
continue; | ||
} | ||
|
||
let updatedProject = false; | ||
if (target.options?.['baseUrl']) { | ||
delete project.targets[targetName].options['baseUrl']; | ||
updatedProject = true; | ||
} | ||
|
||
if ( | ||
project.targets[targetName].configurations && | ||
Object.keys(project.targets[targetName].configurations).length > 0 | ||
) { | ||
for (const [configurationName, configuration] of Object.entries( | ||
project.targets[targetName].configurations | ||
)) { | ||
if (configuration['baseUrl']) { | ||
delete project.targets[targetName].configurations[ | ||
configurationName | ||
]['baseUrl']; | ||
updatedProject = true; | ||
} | ||
} | ||
} | ||
|
||
if (updatedProject) { | ||
updateProjectConfiguration(tree, project.name, project); | ||
} | ||
} | ||
} | ||
|
||
await formatFiles(tree); | ||
} |