-
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.
cleanup(angular): convert ng cli migrations to nx devkit (#15590)
- Loading branch information
Showing
7 changed files
with
267 additions
and
103 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
86 changes: 86 additions & 0 deletions
86
packages/angular/src/migrations/update-15-2-0/remove-platform-server-exports.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,86 @@ | ||
import type { Tree } from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing-pre16'; | ||
|
||
import removePlatformServerExports from './remove-platform-server-exports'; | ||
|
||
describe('remove-platform-server-exports', () => { | ||
let tree: Tree; | ||
const testTypeScriptFilePath = 'test.ts'; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
describe(`Migration to remove '@angular/platform-server' exports`, () => { | ||
it(`should delete '@angular/platform-server' export when 'renderModule' is the only exported symbol`, async () => { | ||
tree.write( | ||
testTypeScriptFilePath, | ||
` | ||
import { Path, join } from '@angular-devkit/core'; | ||
export { renderModule } from '@angular/platform-server'; | ||
` | ||
); | ||
|
||
await removePlatformServerExports(tree); | ||
|
||
const content = tree.read(testTypeScriptFilePath, 'utf-8'); | ||
expect(content).not.toContain('@angular/platform-server'); | ||
expect(content).toContain( | ||
`import { Path, join } from '@angular-devkit/core';` | ||
); | ||
}); | ||
|
||
it(`should delete only 'renderModule' when there are additional exports`, async () => { | ||
tree.write( | ||
testTypeScriptFilePath, | ||
` | ||
import { Path, join } from '@angular-devkit/core'; | ||
export { renderModule, ServerModule } from '@angular/platform-server'; | ||
` | ||
); | ||
|
||
await removePlatformServerExports(tree); | ||
|
||
const content = tree.read(testTypeScriptFilePath, 'utf-8'); | ||
|
||
expect(content).toContain( | ||
`import { Path, join } from '@angular-devkit/core';` | ||
); | ||
expect(content).toContain( | ||
`export { ServerModule } from '@angular/platform-server';` | ||
); | ||
}); | ||
|
||
it(`should not delete 'renderModule' when it's exported from another module`, async () => { | ||
tree.write( | ||
testTypeScriptFilePath, | ||
` | ||
export { renderModule } from '@angular/core'; | ||
` | ||
); | ||
|
||
await removePlatformServerExports(tree); | ||
|
||
const content = tree.read(testTypeScriptFilePath, 'utf-8'); | ||
expect(content).toContain( | ||
`export { renderModule } from '@angular/core';` | ||
); | ||
}); | ||
|
||
it(`should not delete 'renderModule' when it's imported from '@angular/platform-server'`, async () => { | ||
tree.write( | ||
testTypeScriptFilePath, | ||
` | ||
import { renderModule } from '@angular/platform-server'; | ||
` | ||
); | ||
|
||
await removePlatformServerExports(tree); | ||
|
||
const content = tree.read(testTypeScriptFilePath, 'utf-8'); | ||
expect(content).toContain( | ||
`import { renderModule } from '@angular/platform-server'` | ||
); | ||
}); | ||
}); | ||
}); |
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
120 changes: 120 additions & 0 deletions
120
packages/angular/src/migrations/update-15-2-0/update-karma-main-file.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,120 @@ | ||
import type { Tree } from '@nrwl/devkit'; | ||
import { addProjectConfiguration, stripIndents } from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing-pre16'; | ||
import { Builders } from '@schematics/angular/utility/workspace-models'; | ||
import updateKarmaMainFile from './update-karma-main-file'; | ||
|
||
describe(`Migration to karma builder main file (test.ts)`, () => { | ||
let tree: Tree; | ||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
addProjectConfiguration(tree, 'app', { | ||
root: '', | ||
sourceRoot: 'src', | ||
projectType: 'application', | ||
targets: { | ||
test: { | ||
executor: Builders.Karma, | ||
options: { | ||
main: 'test.ts', | ||
karmaConfig: './karma.config.js', | ||
tsConfig: 'test-spec.json', | ||
}, | ||
configurations: { | ||
production: { | ||
main: 'test-multiple-context.ts', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
tree.write( | ||
'test.ts', | ||
stripIndents` | ||
import { getTestBed } from '@angular/core/testing'; | ||
import { | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting | ||
} from '@angular/platform-browser-dynamic/testing'; | ||
declare const require: { | ||
context(path: string, deep?: boolean, filter?: RegExp): { | ||
<T>(id: string): T; | ||
keys(): string[]; | ||
}; | ||
}; | ||
// First, initialize the Angular testing environment. | ||
getTestBed().initTestEnvironment( | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting(), | ||
); | ||
// Then we find all the tests. | ||
const context = require.context('./', true, /\.spec\.ts$/); | ||
// And load the modules. | ||
context.keys().map(context); | ||
` | ||
); | ||
|
||
tree.write( | ||
'test-multiple-context.ts', | ||
stripIndents` | ||
import { getTestBed } from '@angular/core/testing'; | ||
import { | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting | ||
} from '@angular/platform-browser-dynamic/testing'; | ||
declare const require: { | ||
context(path: string, deep?: boolean, filter?: RegExp): { | ||
<T>(id: string): T; | ||
keys(): string[]; | ||
}; | ||
}; | ||
// First, initialize the Angular testing environment. | ||
getTestBed().initTestEnvironment( | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting(), | ||
); | ||
// Then we find all the tests. | ||
const context1 = require.context('./', true, /\.spec\.ts$/); | ||
const context2 = require.context('./', true, /\.spec\.ts$/); | ||
// And load the modules. | ||
context2.keys().forEach(context2); | ||
context1.keys().map(context1); | ||
` | ||
); | ||
}); | ||
|
||
it(`should remove 'declare const require' and 'require.context' usages`, async () => { | ||
await updateKarmaMainFile(tree); | ||
|
||
expect(tree.read('test.ts', 'utf-8')).toBe(stripIndents` | ||
import { getTestBed } from '@angular/core/testing'; | ||
import { | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting | ||
} from '@angular/platform-browser-dynamic/testing'; | ||
// First, initialize the Angular testing environment. | ||
getTestBed().initTestEnvironment( | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting(), | ||
); | ||
`); | ||
}); | ||
|
||
it(`should remove multiple 'require.context' usages`, async () => { | ||
await updateKarmaMainFile(tree); | ||
|
||
expect(tree.read('test-multiple-context.ts', 'utf-8')).toBe(stripIndents` | ||
import { getTestBed } from '@angular/core/testing'; | ||
import { | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting | ||
} from '@angular/platform-browser-dynamic/testing'; | ||
// First, initialize the Angular testing environment. | ||
getTestBed().initTestEnvironment( | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting(), | ||
); | ||
`); | ||
}); | ||
}); |
Oops, something went wrong.