Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(misc): remove deprecated jest builder options from schematic (#3630)
ISSUES CLOSED: #3505
- Loading branch information
Showing
21 changed files
with
224 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ the target Nx Plugin project and build | |
|
||
Type: `string` | ||
|
||
Spec tsconfig file | ||
[Deprecated] Spec tsconfig file |
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 |
---|---|---|
|
@@ -23,4 +23,4 @@ the target Nx Plugin project and build | |
|
||
Type: `string` | ||
|
||
Spec tsconfig file | ||
[Deprecated] Spec tsconfig file |
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
78 changes: 78 additions & 0 deletions
78
packages/jest/src/migrations/update-10-2-0/update-10-2-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,78 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
import { serializeJson } from '@nrwl/workspace'; | ||
import { createEmptyWorkspace } from '@nrwl/workspace/testing'; | ||
import * as path from 'path'; | ||
|
||
describe('update 10.2.0', () => { | ||
let initialTree: Tree; | ||
let schematicRunner: SchematicTestRunner; | ||
|
||
beforeEach(() => { | ||
initialTree = createEmptyWorkspace(Tree.empty()); | ||
|
||
initialTree.overwrite( | ||
'workspace.json', | ||
serializeJson({ | ||
version: 1, | ||
projects: { | ||
products: { | ||
root: 'apps/products', | ||
sourceRoot: 'apps/products/src', | ||
architect: { | ||
build: { | ||
builder: '@angular-devkit/build-angular:browser', | ||
}, | ||
test: { | ||
builder: '@nrwl/jest:jest', | ||
options: { | ||
jestConfig: 'apps/products/jest.config.js', | ||
tsConfig: 'apps/products/tsconfig.spec.json', | ||
setupFile: 'apps/products/src/test-setup.ts', | ||
passWithNoTests: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
cart: { | ||
root: 'apps/cart', | ||
sourceRoot: 'apps/cart/src', | ||
architect: { | ||
build: { | ||
builder: '@nrwl/web:build', | ||
}, | ||
test: { | ||
builder: '@nrwl/jest:jest', | ||
options: { | ||
jestConfig: 'apps/cart/jest.config.js', | ||
passWithNoTests: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
); | ||
schematicRunner = new SchematicTestRunner( | ||
'@nrwl/jest', | ||
path.join(__dirname, '../../../migrations.json') | ||
); | ||
}); | ||
|
||
it('should remove setupFile and tsconfig in test architect from workspace.json', async (done) => { | ||
const result = await schematicRunner | ||
.runSchematicAsync('update-10.2.0', {}, initialTree) | ||
.toPromise(); | ||
|
||
const updatedWorkspace = JSON.parse(result.readContent('workspace.json')); | ||
expect(updatedWorkspace.projects.products.architect.test.options).toEqual({ | ||
jestConfig: expect.anything(), | ||
passWithNoTests: expect.anything(), | ||
}); | ||
expect(updatedWorkspace.projects.cart.architect.test.options).toEqual({ | ||
jestConfig: expect.anything(), | ||
passWithNoTests: expect.anything(), | ||
}); | ||
done(); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
packages/jest/src/migrations/update-10-2-0/update-10-2-0.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,33 @@ | ||
import { chain, Rule, Tree } from '@angular-devkit/schematics'; | ||
import { | ||
formatFiles, | ||
getWorkspace, | ||
getWorkspacePath, | ||
updateWorkspace, | ||
} from '@nrwl/workspace'; | ||
|
||
function removeDeprecatedJestBuilderOptions() { | ||
return async (host: Tree) => { | ||
const workspace = await getWorkspace(host, getWorkspacePath(host)); | ||
|
||
for (const [, projectDefinition] of workspace.projects) { | ||
for (const [, testTarget] of projectDefinition.targets) { | ||
if (testTarget.builder !== '@nrwl/jest:jest') { | ||
continue; | ||
} | ||
|
||
const updatedOptions = { ...testTarget.options }; | ||
delete updatedOptions.setupFile; | ||
delete updatedOptions.tsConfig; | ||
|
||
testTarget.options = updatedOptions; | ||
} | ||
} | ||
|
||
return updateWorkspace(workspace); | ||
}; | ||
} | ||
|
||
export default function update(): Rule { | ||
return chain([removeDeprecatedJestBuilderOptions(), formatFiles()]); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
{ | ||
"schematics": {} | ||
"schematics": { | ||
"update-10.2.0": { | ||
"version": "10.2.0", | ||
"description": "Remove deprecated jest builder options", | ||
"factory": "./src/migrations/update-10-2-0/update-10-2-0" | ||
} | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-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,61 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
import { serializeJson } from '@nrwl/workspace'; | ||
import { createEmptyWorkspace } from '@nrwl/workspace/testing'; | ||
import * as path from 'path'; | ||
|
||
describe('update 10.2.0', () => { | ||
let initialTree: Tree; | ||
let schematicRunner: SchematicTestRunner; | ||
|
||
beforeEach(() => { | ||
initialTree = createEmptyWorkspace(Tree.empty()); | ||
|
||
initialTree.overwrite( | ||
'workspace.json', | ||
serializeJson({ | ||
version: 1, | ||
projects: { | ||
'my-plugin-e2e': { | ||
projectType: 'application', | ||
root: 'apps/my-plugin-e2e', | ||
sourceRoot: 'apps/my-plugin-e2e/src', | ||
architect: { | ||
e2e: { | ||
builder: '@nrwl/nx-plugin:e2e', | ||
options: { | ||
target: 'my-plugin:build', | ||
npmPackageName: '@repo/my-plugin', | ||
pluginOutputPath: 'dist/libs/my-plugin', | ||
jestConfig: 'apps/my-plugin-e2e/jest.config.js', | ||
tsSpecConfig: 'apps/my-plugin-e2e/tsconfig.spec.json', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
); | ||
schematicRunner = new SchematicTestRunner( | ||
'@nrwl/jest', | ||
path.join(__dirname, '../../../migrations.json') | ||
); | ||
}); | ||
|
||
it('should remove setupFile and tsconfig in test architect from workspace.json', async (done) => { | ||
const result = await schematicRunner | ||
.runSchematicAsync('update-10.2.0', {}, initialTree) | ||
.toPromise(); | ||
|
||
const updatedWorkspace = JSON.parse(result.readContent('workspace.json')); | ||
expect( | ||
updatedWorkspace.projects['my-plugin-e2e'].architect.e2e.options | ||
).toEqual({ | ||
target: expect.anything(), | ||
npmPackageName: expect.anything(), | ||
pluginOutputPath: expect.anything(), | ||
jestConfig: expect.anything(), | ||
}); | ||
done(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.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 { chain, Rule, Tree } from '@angular-devkit/schematics'; | ||
import { | ||
formatFiles, | ||
getWorkspace, | ||
getWorkspacePath, | ||
updateWorkspace, | ||
} from '@nrwl/workspace'; | ||
|
||
function removeDeprecatedJestBuilderOptions() { | ||
return async (host: Tree) => { | ||
const workspace = await getWorkspace(host, getWorkspacePath(host)); | ||
|
||
for (const [, projectDefinition] of workspace.projects) { | ||
for (const [, testTarget] of projectDefinition.targets) { | ||
if (testTarget.builder !== '@nrwl/nx-plugin:e2e') { | ||
continue; | ||
} | ||
|
||
const updatedOptions = { ...testTarget.options }; | ||
delete updatedOptions.tsSpecConfig; | ||
|
||
testTarget.options = updatedOptions; | ||
} | ||
} | ||
|
||
return updateWorkspace(workspace); | ||
}; | ||
} | ||
|
||
export default function update(): Rule { | ||
return chain([removeDeprecatedJestBuilderOptions(), formatFiles()]); | ||
} |
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