-
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.
feat(vite): allow passing multiple test files to vite:test (#17496)
Co-authored-by: Caleb Ukle <caleb.ukle+github@pm.me>
- Loading branch information
1 parent
c4b7a1f
commit a995940
Showing
7 changed files
with
163 additions
and
8 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
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
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
106 changes: 106 additions & 0 deletions
106
...c/migrations/update-16-4-1-update-test-file-config/update-16-4-1-test-file-config.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,106 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import { | ||
Tree, | ||
addProjectConfiguration, | ||
readProjectConfiguration, | ||
} from '@nx/devkit'; | ||
|
||
import updateTestFileOption from './update-16-4-1-test-file-config'; | ||
|
||
describe('update-16-5-0-vite-test-file-config migration', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); | ||
}); | ||
|
||
it('should run successfully when testFile does not exist in the config', () => { | ||
addProjectConfiguration(tree, 'vitest', { | ||
root: 'vitest', | ||
targets: { | ||
test: { | ||
executor: '@nx/vite:test', | ||
options: { | ||
ci: true, | ||
watch: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
updateTestFileOption(tree); | ||
expect(readProjectConfiguration(tree, 'vitest')).toMatchInlineSnapshot(` | ||
{ | ||
"$schema": "../node_modules/nx/schemas/project-schema.json", | ||
"name": "vitest", | ||
"root": "vitest", | ||
"targets": { | ||
"test": { | ||
"executor": "@nx/vite:test", | ||
"options": { | ||
"ci": true, | ||
"watch": true, | ||
}, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
it('should run successfully when testFile exists in options and configurations', () => { | ||
addProjectConfiguration(tree, 'vitest', { | ||
root: 'vitest', | ||
targets: { | ||
test: { | ||
executor: '@nx/vite:test', | ||
options: { | ||
testFile: 'test-file.ts', | ||
config: 'vite.config.ts', | ||
}, | ||
configurations: { | ||
one: { | ||
testFile: 'test-file-one.ts', | ||
ci: true, | ||
}, | ||
two: { | ||
testFile: 'test-file-two.ts', | ||
watch: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
updateTestFileOption(tree); | ||
expect(readProjectConfiguration(tree, 'vitest')).toMatchInlineSnapshot(` | ||
{ | ||
"$schema": "../node_modules/nx/schemas/project-schema.json", | ||
"name": "vitest", | ||
"root": "vitest", | ||
"targets": { | ||
"test": { | ||
"configurations": { | ||
"one": { | ||
"ci": true, | ||
"testFiles": [ | ||
"test-file-one.ts", | ||
], | ||
}, | ||
"two": { | ||
"testFiles": [ | ||
"test-file-two.ts", | ||
], | ||
"watch": true, | ||
}, | ||
}, | ||
"executor": "@nx/vite:test", | ||
"options": { | ||
"config": "vite.config.ts", | ||
"testFiles": [ | ||
"test-file.ts", | ||
], | ||
}, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
...te/src/migrations/update-16-4-1-update-test-file-config/update-16-4-1-test-file-config.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,41 @@ | ||
import { Tree, getProjects, updateProjectConfiguration } from '@nx/devkit'; | ||
import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; | ||
import { VitestExecutorOptions } from '../../executors/test/schema'; | ||
|
||
type OldVitestExecutorOptions = Omit<VitestExecutorOptions, 'testFiles'> & { | ||
testFile: string; | ||
}; | ||
|
||
export default function update(tree: Tree) { | ||
const projects = getProjects(tree); | ||
|
||
forEachExecutorOptions<OldVitestExecutorOptions>( | ||
tree, | ||
'@nx/vite:test', | ||
(options, projectName, targetName, configuration) => { | ||
const projectConfig = projects.get(projectName); | ||
|
||
if (!options.testFile) { | ||
return; | ||
} | ||
|
||
const newTestFileArgs = [options.testFile]; | ||
|
||
delete options.testFile; | ||
|
||
if (configuration) { | ||
projectConfig.targets[targetName].configurations[configuration] = { | ||
...options, | ||
testFiles: newTestFileArgs, | ||
}; | ||
} else { | ||
projectConfig.targets[targetName].options = { | ||
...options, | ||
testFiles: newTestFileArgs, | ||
}; | ||
} | ||
|
||
updateProjectConfiguration(tree, projectName, projectConfig); | ||
} | ||
); | ||
} |
a995940
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev