-
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): correctly set task status for failed coverage repos
- Loading branch information
1 parent
181cde5
commit 6dcf20e
Showing
8 changed files
with
289 additions
and
10 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
148 changes: 148 additions & 0 deletions
148
packages/vite/src/migrations/update-15-4-1/update-report-directory.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,148 @@ | ||
import { | ||
addProjectConfiguration, | ||
readProjectConfiguration, | ||
Tree, | ||
} from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { updateReportDirectoryPlaceholders } from './update-report-directory'; | ||
|
||
describe('Update Report Directory Vitest Migration', () => { | ||
let tree: Tree; | ||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should migrate', () => { | ||
addVitestProjects(tree, { name: 'project' }); | ||
|
||
updateReportDirectoryPlaceholders(tree); | ||
expect(readProjectConfiguration(tree, 'project-one').targets) | ||
.toMatchInlineSnapshot(` | ||
Object { | ||
"test": Object { | ||
"executor": "@nrwl/vite:test", | ||
"options": Object { | ||
"passWithNoTests": true, | ||
"reportsDirectory": "coverge/packages/project-one", | ||
}, | ||
"outputs": Array [ | ||
"coverage/packages/project-one", | ||
], | ||
}, | ||
} | ||
`); | ||
expect(readProjectConfiguration(tree, 'project-two').targets) | ||
.toMatchInlineSnapshot(` | ||
Object { | ||
"custom-test": Object { | ||
"configurations": Object { | ||
"ci": Object { | ||
"reportsDirectory": "coverge/project-two", | ||
}, | ||
}, | ||
"executor": "@nrwl/vite:test", | ||
"options": Object { | ||
"passWithNoTests": true, | ||
}, | ||
"outputs": Array [ | ||
"coverage/project-two", | ||
"dist/coverage/else.txt", | ||
], | ||
}, | ||
"test": Object { | ||
"executor": "@nrwl/vite:test", | ||
"options": Object { | ||
"passWithNoTests": true, | ||
"reportsDirectory": "coverge/project-two", | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
it('should be idempotent', () => { | ||
addVitestProjects(tree, { name: 'project' }); | ||
|
||
const expectedProjectOneConfig = { | ||
test: { | ||
outputs: ['coverage/packages/project-one'], | ||
executor: '@nrwl/vite:test', | ||
options: { | ||
reportsDirectory: 'coverge/packages/project-one', | ||
passWithNoTests: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedProjectTwoConfig = { | ||
'custom-test': { | ||
executor: '@nrwl/vite:test', | ||
outputs: ['coverage/project-two', 'dist/coverage/else.txt'], | ||
options: { | ||
passWithNoTests: true, | ||
}, | ||
configurations: { | ||
ci: { | ||
reportsDirectory: 'coverge/project-two', | ||
}, | ||
}, | ||
}, | ||
test: { | ||
executor: '@nrwl/vite:test', | ||
options: { | ||
reportsDirectory: 'coverge/project-two', | ||
passWithNoTests: true, | ||
}, | ||
}, | ||
}; | ||
|
||
updateReportDirectoryPlaceholders(tree); | ||
const projOneConfig = readProjectConfiguration(tree, 'project-one'); | ||
expect(projOneConfig.targets).toEqual(expectedProjectOneConfig); | ||
const projTwoConfig = readProjectConfiguration(tree, 'project-two'); | ||
expect(projTwoConfig.targets).toEqual(expectedProjectTwoConfig); | ||
}); | ||
}); | ||
|
||
function addVitestProjects(tree: Tree, options: { name: string }) { | ||
addProjectConfiguration(tree, options.name + '-one', { | ||
name: options.name + '-one', | ||
sourceRoot: `packages/${options.name}-one/src`, | ||
root: `packages/${options.name}-one`, | ||
targets: { | ||
test: { | ||
outputs: ['{projectRoot}/coverage'], | ||
executor: '@nrwl/vite:test', | ||
options: { | ||
reportsDirectory: '{workspaceRoot}/coverge/{projectRoot}', | ||
passWithNoTests: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
addProjectConfiguration(tree, options.name + '-two', { | ||
name: options.name + '-two', | ||
sourceRoot: 'src', | ||
root: '.', | ||
targets: { | ||
'custom-test': { | ||
executor: '@nrwl/vite:test', | ||
outputs: ['{projectRoot}/coverage', 'dist/coverage/else.txt'], | ||
options: { | ||
passWithNoTests: true, | ||
}, | ||
configurations: { | ||
ci: { | ||
reportsDirectory: '{workspaceRoot}/coverge/{projectRoot}', | ||
}, | ||
}, | ||
}, | ||
test: { | ||
executor: '@nrwl/vite:test', | ||
options: { | ||
reportsDirectory: '{workspaceRoot}/coverge/{projectRoot}', | ||
passWithNoTests: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/vite/src/migrations/update-15-4-1/update-report-directory.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,42 @@ | ||
import { getProjects, Tree, updateProjectConfiguration } from '@nrwl/devkit'; | ||
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; | ||
import { VitestExecutorOptions } from '../../executors/test/schema'; | ||
|
||
export function updateReportDirectoryPlaceholders(tree: Tree) { | ||
const projects = getProjects(tree); | ||
forEachExecutorOptions<VitestExecutorOptions>( | ||
tree, | ||
'@nrwl/vite:test', | ||
(options, projectName, targetName, configName) => { | ||
const projectConfig = projects.get(projectName); | ||
const coverageOutput = | ||
projectConfig.root === '.' ? projectName : projectConfig.root; | ||
|
||
if (options.reportsDirectory) { | ||
options.reportsDirectory = options.reportsDirectory | ||
.replace('{workspaceRoot}/', '') | ||
.replace('{projectRoot}', coverageOutput); | ||
console.log({ options, projectName, configName, coverageOutput }); | ||
if (configName) { | ||
projectConfig.targets[targetName].configurations[configName] = | ||
options; | ||
} else { | ||
projectConfig.targets[targetName].options = options; | ||
} | ||
if (projectConfig.targets[targetName].outputs) { | ||
projectConfig.targets[targetName].outputs = projectConfig.targets[ | ||
targetName | ||
].outputs.map((output) => | ||
output.replace( | ||
'{projectRoot}/coverage', | ||
`coverage/${coverageOutput}` | ||
) | ||
); | ||
} | ||
updateProjectConfiguration(tree, projectName, projectConfig); | ||
} | ||
} | ||
); | ||
} | ||
|
||
export default updateReportDirectoryPlaceholders; |
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