forked from AmadeusITGroup/otter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
161 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/angular/angular-cli/master/packages/angular_devkit/schematics/collection-schema.json", | ||
"schematics": { | ||
"ng-update": { | ||
"migration-v10_0": { | ||
"version": "10.0.0-alpha.0", | ||
"description": "Updates of the Otter Application module to v10.0.x", | ||
"factory": "./schematics/ng-update/index#ngUpdate" | ||
"description": "Updates of @o3r/application to v10.0.*", | ||
"factory": "./schematics/ng-update/index#updateV10_0" | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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
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
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
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
84 changes: 84 additions & 0 deletions
84
packages/@o3r/schematics/src/utility/update-imports.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,84 @@ | ||
import {logging} from '@angular-devkit/core'; | ||
import {Tree} from '@angular-devkit/schematics'; | ||
import {updateImportsInFile} from '@o3r/schematics'; | ||
import * as ts from 'typescript'; | ||
|
||
describe('updateImportsInFile', () => { | ||
const logger = { | ||
debug: jest.fn(), | ||
info: jest.fn(), | ||
log: jest.fn(), | ||
warn: jest.fn(), | ||
error: jest.fn() | ||
} as any as logging.Logger; | ||
|
||
it('should replace imports in a file', () => { | ||
const fileName = 'test.ts'; | ||
const originalFileContent = ` | ||
import {DontTouchThis} from 'leave-me-alone'; | ||
import {MyAwesomeService, MyVeryOldService} from 'my-decent-package'; | ||
const myVeryOldService = new MyVeryOldService(); | ||
`; | ||
const tree = Tree.empty(); | ||
tree.create(fileName, originalFileContent); | ||
const sourceFile = ts.createSourceFile(fileName, originalFileContent, ts.ScriptTarget.ES2015, true); | ||
const importsRegexp = /^MyVeryOldService$/; | ||
const renamePackagesRegexp = /^my-decent-package$/; | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
const mapImports = { | ||
'my-decent-package': { | ||
MyVeryOldService: { | ||
newPackage: 'my-brand-new-package', | ||
newValue: 'MyVeryNewService' | ||
} | ||
} | ||
}; | ||
const renamedPackages = {}; | ||
/* eslint-enable @typescript-eslint/naming-convention */ | ||
|
||
const unresolvedImports = updateImportsInFile(logger, tree, sourceFile, importsRegexp, renamePackagesRegexp, mapImports, renamedPackages); | ||
const finalFileContent = tree.readText(fileName); | ||
|
||
expect(unresolvedImports).toBe(1); | ||
expect(finalFileContent).toContain('import {DontTouchThis} from \'leave-me-alone\';'); | ||
expect(finalFileContent).toContain('import {MyAwesomeService} from \'my-decent-package\';'); | ||
expect(finalFileContent).toContain('import {MyVeryNewService} from \'my-brand-new-package\';'); | ||
expect(finalFileContent).toContain('const myVeryOldService = new MyVeryNewService();'); | ||
}); | ||
|
||
it('should rename packages', () => { | ||
const fileName = 'test.ts'; | ||
const originalFileContent = ` | ||
import {DontTouchThis} from 'leave-me-alone'; | ||
import {MyAwesomeService, MyVeryOldService} from 'my-decent-package'; | ||
const myVeryOldService = new MyVeryOldService(); | ||
`; | ||
const tree = Tree.empty(); | ||
tree.create(fileName, originalFileContent); | ||
const sourceFile = ts.createSourceFile(fileName, originalFileContent, ts.ScriptTarget.ES2015, true); | ||
const importsRegexp = /^MyVeryOldService$/; | ||
const renamePackagesRegexp = /^my-decent-package$/; | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
const mapImports = { | ||
'my-decent-package': { | ||
MyVeryOldService: { | ||
newPackage: 'my-brand-new-package', | ||
newValue: 'MyVeryNewService' | ||
} | ||
} | ||
}; | ||
const renamedPackages = { | ||
'my-decent-package': 'my-slightly-better-package' | ||
}; | ||
/* eslint-enable @typescript-eslint/naming-convention */ | ||
|
||
const unresolvedImports = updateImportsInFile(logger, tree, sourceFile, importsRegexp, renamePackagesRegexp, mapImports, renamedPackages); | ||
const finalFileContent = tree.readText(fileName); | ||
|
||
expect(unresolvedImports).toBe(0); | ||
expect(finalFileContent).toContain('import {DontTouchThis} from \'leave-me-alone\';'); | ||
expect(finalFileContent).toContain('import {MyAwesomeService, MyVeryNewService} from \'my-slightly-better-package\';'); | ||
expect(finalFileContent).toContain('const myVeryOldService = new MyVeryNewService();'); | ||
expect(finalFileContent).not.toContain('my-decent-package'); | ||
}); | ||
}); |
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
Oops, something went wrong.