-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Steve Brush <steve.brush@blackbaud.com>
- Loading branch information
1 parent
4e360ee
commit 7221b5e
Showing
7 changed files
with
141 additions
and
7 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
92 changes: 92 additions & 0 deletions
92
...mponents/packages/src/schematics/migrations/update-11/axe-core/axe-core.schematic.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,92 @@ | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
|
||
import { resolve } from 'path'; | ||
|
||
import { createTestLibrary } from '../../../testing/scaffold'; | ||
|
||
describe('axe-core.schematic', () => { | ||
const runner = new SchematicTestRunner( | ||
'migrations', | ||
resolve(__dirname, '../../migration-collection.json'), | ||
); | ||
|
||
async function setupTest(options?: { | ||
packageJson?: { | ||
dependencies?: Record<string, string>; | ||
devDependencies?: Record<string, string>; | ||
}; | ||
}) { | ||
const tree = await createTestLibrary(runner, { | ||
projectName: 'my-lib', | ||
}); | ||
|
||
tree.overwrite('/package.json', JSON.stringify(options?.packageJson ?? {})); | ||
|
||
return { | ||
runSchematic: () => runner.runSchematic('axe-core', {}, tree), | ||
tree, | ||
}; | ||
} | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should update axe-core version if @skyux-sdk/testing installed', async () => { | ||
const { runSchematic, tree } = await setupTest({ | ||
packageJson: { | ||
dependencies: { | ||
'axe-core': '*', | ||
}, | ||
devDependencies: { | ||
'@skyux-sdk/testing': '*', | ||
}, | ||
}, | ||
}); | ||
|
||
await runSchematic(); | ||
|
||
expect(JSON.parse(tree.readText('package.json'))).toEqual({ | ||
dependencies: {}, | ||
devDependencies: { | ||
'@skyux-sdk/testing': '*', | ||
'axe-core': '~4.10.0', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should abort if @skyux-sdk/testing not installed', async () => { | ||
const { runSchematic, tree } = await setupTest({ | ||
packageJson: { | ||
devDependencies: { | ||
'axe-core': '*', | ||
}, | ||
}, | ||
}); | ||
|
||
await runSchematic(); | ||
|
||
expect(JSON.parse(tree.readText('package.json'))).toEqual({ | ||
devDependencies: { 'axe-core': '*' }, | ||
}); | ||
}); | ||
|
||
it('should install axe-core if @skyux-sdk/testing installed without', async () => { | ||
const { runSchematic, tree } = await setupTest({ | ||
packageJson: { | ||
devDependencies: { | ||
'@skyux-sdk/testing': '*', | ||
}, | ||
}, | ||
}); | ||
|
||
await runSchematic(); | ||
|
||
expect(JSON.parse(tree.readText('package.json'))).toEqual({ | ||
devDependencies: { | ||
'@skyux-sdk/testing': '*', | ||
'axe-core': '~4.10.0', | ||
}, | ||
}); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
libs/components/packages/src/schematics/migrations/update-11/axe-core/axe-core.schematic.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,37 @@ | ||
import { Rule } from '@angular-devkit/schematics'; | ||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; | ||
import { | ||
NodeDependency, | ||
NodeDependencyType, | ||
addPackageJsonDependency, | ||
getPackageJsonDependency, | ||
removePackageJsonDependency, | ||
} from '@schematics/angular/utility/dependencies'; | ||
|
||
const AXE_CORE_PACKAGE = 'axe-core'; | ||
const AXE_CORE_VERSION = '~4.10.0'; | ||
|
||
/** | ||
* Sets axe-core to ~4.10.0. We can't put this in the ng-update.packageGroup | ||
* because we only want to update a customer's axe-core version if they've | ||
* installed @skyux-sdk/testing. | ||
*/ | ||
export default function updateAxeCore(): Rule { | ||
return (tree, context) => { | ||
if (getPackageJsonDependency(tree, '@skyux-sdk/testing') !== null) { | ||
const axeCore: NodeDependency = { | ||
name: AXE_CORE_PACKAGE, | ||
version: AXE_CORE_VERSION, | ||
type: NodeDependencyType.Dev, | ||
overwrite: true, | ||
}; | ||
|
||
const packageJsonPath = '/package.json'; | ||
|
||
removePackageJsonDependency(tree, AXE_CORE_PACKAGE, packageJsonPath); | ||
addPackageJsonDependency(tree, axeCore, packageJsonPath); | ||
} | ||
|
||
context.addTask(new NodePackageInstallTask()); | ||
}; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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