-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(schematics): run tests for template files (#12562)
- Loading branch information
1 parent
f8b70cd
commit 7756882
Showing
19 changed files
with
143 additions
and
92 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/* | ||
* NOTE: This file will run before the actual tests start inside of Bazel. | ||
* | ||
* It automatically runs before all spec files because the spec files are blocked | ||
* until Jasmine runs the `describe` blocks. | ||
* | ||
* We copy all needed files into the proper Bazel bin output in order to be able to test | ||
* the schematics. Workaround for: https://github.com/bazelbuild/rules_typescript/issues/154 | ||
*/ | ||
|
||
import {sync as globSync} from 'glob'; | ||
import {dirname, join} from 'path'; | ||
import {copySync} from 'fs-extra'; | ||
|
||
// Adding the test case files to the data of the `jasmine_node_test` Bazel rule does not mean | ||
// that the files are being copied over to the Bazel bin output. Bazel just patches the NodeJS | ||
// resolve function and maps the module paths to the original file location. Since we want to copy | ||
// the files to the bazel test directory because TSLint and the schematic test runner expect a real | ||
// file system, we need to resolve the original file path through a Bazel mapped file. | ||
const sourceDirectory = dirname( | ||
require.resolve('angular_material/src/lib/schematics/collection.json')); | ||
|
||
const bazelBinDir = join(__dirname, '../'); | ||
|
||
// Copy all schema files to the bazel bin directory. | ||
globSync('**/schema.json', {cwd: sourceDirectory}) | ||
.forEach(file => copySync(join(sourceDirectory, file), join(bazelBinDir, file))); | ||
|
||
// Copy all template files to the bazel bin directory. | ||
globSync('**/files/**/*', {cwd: sourceDirectory}) | ||
.forEach(file => copySync(join(sourceDirectory, file), join(bazelBinDir, file))); | ||
|
||
// Copy the collection.json and migration.json file to the bazel bin directory. | ||
globSync('+(collection|migration).json', {cwd: sourceDirectory}) | ||
.forEach(file => copySync(join(sourceDirectory, file), join(bazelBinDir, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; | ||
import {join} from 'path'; | ||
|
||
/** Path to the collection file for the Material schematics */ | ||
export const collectionPath = join(__dirname, '..', 'collection.json'); | ||
|
||
/** Path to the migration file for the Material update schematics */ | ||
export const migrationCollection = join(__dirname, '..', 'migration.json'); | ||
|
||
/** Create a base app used for testing. */ | ||
export function createTestApp(): UnitTestTree { | ||
const baseRunner = new SchematicTestRunner('material-schematics', collectionPath); | ||
|
||
const workspaceTree = baseRunner.runExternalSchematic('@schematics/angular', 'workspace', { | ||
name: 'workspace', | ||
version: '6.0.0', | ||
newProjectRoot: 'projects', | ||
}); | ||
|
||
return baseRunner.runExternalSchematic('@schematics/angular', 'application', { | ||
name: 'material', | ||
inlineStyle: false, | ||
inlineTemplate: false, | ||
routing: false, | ||
style: 'scss', | ||
skipTests: false, | ||
}, workspaceTree); | ||
} |
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.