-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nx): exclude appropriate test setup file in tsconfig.lib.json
Resolves #1139
- Loading branch information
1 parent
0b72c63
commit eeb713f
Showing
6 changed files
with
210 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
32 changes: 32 additions & 0 deletions
32
packages/workspace/src/migrations/update-8-5-0/fix-tsconfig-lib-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,32 @@ | ||
import { Tree, SchematicContext } from '@angular-devkit/schematics'; | ||
import { readWorkspace, readJsonInTree } from '../../utils/ast-utils'; | ||
|
||
export default function() { | ||
return (host: Tree) => { | ||
const config = readWorkspace(host); | ||
|
||
const configsToUpdate = []; | ||
Object.keys(config.projects).forEach(name => { | ||
const project = config.projects[name]; | ||
if ( | ||
project.projectType === 'library' && | ||
project.architect && | ||
project.architect.test && | ||
project.architect.test.builder === '@nrwl/jest:test' && | ||
project.architect.test.options && | ||
project.architect.test.options.setupFile === | ||
project.sourceRoot + '/test-setup.ts' | ||
) { | ||
configsToUpdate.push(project.root + '/tsconfig.lib.json'); | ||
} | ||
}); | ||
|
||
configsToUpdate.forEach(config => { | ||
const tsconfig = readJsonInTree(host, config); | ||
if (tsconfig.exclude && tsconfig.exclude[0] === 'src/test.ts') { | ||
tsconfig.exclude[0] = 'src/test-setup.ts'; | ||
host.overwrite(config, JSON.stringify(tsconfig)); | ||
} | ||
}); | ||
}; | ||
} |
97 changes: 97 additions & 0 deletions
97
packages/workspace/src/migrations/update-8-5-0/update-8-5-0.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,97 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
import { join } from 'path'; | ||
import { readJsonInTree } from '@nrwl/workspace'; | ||
import { createEmptyWorkspace } from '@nrwl/workspace/testing'; | ||
import { createLibWithTests } from '../../utils/testing'; | ||
|
||
describe('Update 8.5.0', () => { | ||
let tree: Tree; | ||
let schematicRunner: SchematicTestRunner; | ||
|
||
const jestBuilder = '@nrwl/jest:test'; | ||
const nonJestBuilder = 'something-else'; | ||
|
||
beforeEach(async () => { | ||
tree = Tree.empty(); | ||
tree = createEmptyWorkspace(tree); | ||
schematicRunner = new SchematicTestRunner( | ||
'@nrwl/workspace', | ||
join(__dirname, '../../../migrations.json') | ||
); | ||
}); | ||
|
||
describe('When fixing tsconfig.lib.json files', () => { | ||
const schematicName = 'fix-tsconfig-lib-json'; | ||
|
||
it('should not modify non jest projects', async () => { | ||
const lib = 'non-jest-lib'; | ||
const exclude = [`src/test.ts`, '**/*.spec.ts']; | ||
|
||
tree = await createLibWithTests(tree, lib, nonJestBuilder, 'test.ts'); | ||
tree.create( | ||
`/libs/${lib}/tsconfig.lib.json`, | ||
JSON.stringify({ exclude }) | ||
); | ||
|
||
const result = await schematicRunner | ||
.runSchematicAsync(schematicName, {}, tree) | ||
.toPromise(); | ||
|
||
const tsconfigJson = readJsonInTree( | ||
result, | ||
`libs/${lib}/tsconfig.lib.json` | ||
); | ||
expect(tsconfigJson.exclude).toEqual(exclude); | ||
}); | ||
|
||
it('should modify untouched jest projects', async () => { | ||
const lib = 'jest-lib'; | ||
const exclude = [`src/test.ts`, '**/*.spec.ts']; | ||
const expected = ['src/test-setup.ts', '**/*.spec.ts']; | ||
|
||
tree = await createLibWithTests(tree, lib, jestBuilder, 'test-setup.ts'); | ||
tree.create( | ||
`/libs/${lib}/tsconfig.lib.json`, | ||
JSON.stringify({ exclude }) | ||
); | ||
|
||
const result = await schematicRunner | ||
.runSchematicAsync(schematicName, {}, tree) | ||
.toPromise(); | ||
|
||
const tsconfigJson = readJsonInTree( | ||
result, | ||
`libs/${lib}/tsconfig.lib.json` | ||
); | ||
|
||
expect(tsconfigJson.exclude).toEqual(expected); | ||
}); | ||
|
||
it('should not touch modified jest projects', async () => { | ||
const lib = 'modified-jest-lib'; | ||
const exclude = [`src/test-modified.ts`, '**/*.spec.ts']; | ||
|
||
tree = await createLibWithTests( | ||
tree, | ||
lib, | ||
jestBuilder, | ||
'test-modified.ts.ts' | ||
); | ||
tree.create( | ||
`/libs/${lib}/tsconfig.lib.json`, | ||
JSON.stringify({ exclude }) | ||
); | ||
|
||
const result = await schematicRunner | ||
.runSchematicAsync(schematicName, {}, tree) | ||
.toPromise(); | ||
|
||
const tsconfigJson = readJsonInTree( | ||
result, | ||
`libs/${lib}/tsconfig.lib.json` | ||
); | ||
expect(tsconfigJson.exclude).toEqual(exclude); | ||
}); | ||
}); | ||
}); |
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