@@ -2,41 +2,41 @@ import {getSystemPath, normalize, virtualFs} from '@angular-devkit/core';
2
2
import { TempScopedNodeJsSyncHost } from '@angular-devkit/core/node/testing' ;
3
3
import { SchematicTestRunner } from '@angular-devkit/schematics/testing' ;
4
4
import { readFileSync } from 'fs' ;
5
- import { join } from 'path' ;
5
+ import { join , dirname } from 'path' ;
6
6
import { createTestApp , migrationCollection , runPostScheduledTasks } from '../../utils/testing' ;
7
7
8
- describe ( 'update fixtures ' , ( ) => {
8
+ describe ( 'test cases ' , ( ) => {
9
9
10
10
/**
11
- * Path to directories that contain a testing fixture and result fixture . These fixtures
12
- * will be used to verify the update schematic .
11
+ * Path to directories that contain a test case for the update schematics . These test cases
12
+ * will be used to verify that update schematics properly update developer's applications .
13
13
*/
14
- const fixturesDirectories = [
14
+ const testCaseDirs = [
15
15
'angular_material/src/lib/schematics/update/tests/class-names' ,
16
16
] ;
17
17
18
- // Iterates through every fixture directory and generates a jasmine test block that will verify
19
- // that the update schematics properly update the test fixture to the expected fixture .
20
- fixturesDirectories . forEach ( fixtureDirPath => {
18
+ // Iterates through every test case directory and generates a jasmine test block that will
19
+ // verify that the update schematics properly update the test input to the expected output .
20
+ testCaseDirs . forEach ( testCaseDir => {
21
21
22
- // Adding the fixture files to the data of the `jasmine_node_test` Bazel rule does not mean
23
- // that the fixtures are being copied over to the bin output. Bazel just patches the NodeJS
24
- // resolve function in order to map the module paths to the original file location. Since we
25
- // need to load the content of those fixtures , we need to resolve the original file path.
26
- const testFixturePath = require . resolve ( join ( fixtureDirPath , 'test.fixture ' ) ) ;
27
- const expectedFixturePath = require . resolve ( join ( fixtureDirPath , 'expected.fixture ' ) ) ;
22
+ // Adding the test case files to the data of the `jasmine_node_test` Bazel rule does not mean
23
+ // that the files are being copied over to the Bazel bin output. Bazel just patches the NodeJS
24
+ // resolve function and maps the module paths to the original file location. Since we
25
+ // need to load the content of those test cases , we need to resolve the original file path.
26
+ const inputPath = require . resolve ( join ( testCaseDir , 'input.ts ' ) ) ;
27
+ const expectedOutputPath = require . resolve ( join ( testCaseDir , 'expected_output.ts ' ) ) ;
28
28
29
- it ( `should properly update fixture " ${ fixtureDirPath } " with the update schematic ` , ( ) => {
29
+ it ( `should apply update schematics to test case: ${ dirname ( testCaseDir ) } ` , ( ) => {
30
30
const runner = new SchematicTestRunner ( 'schematics' , migrationCollection ) ;
31
31
32
- runner . runSchematic ( 'migration-01' , { } , createTestAppWithFixture ( testFixturePath ) ) ;
32
+ runner . runSchematic ( 'migration-01' , { } , createTestAppWithTestCase ( inputPath ) ) ;
33
33
34
34
// Run the scheduled TSLint fix task from the update schematic. This task is responsible for
35
35
// identifying outdated code parts and performs the fixes. Since tasks won't run automatically
36
36
// within a `SchematicTestRunner`, we manually need to run the scheduled task.
37
37
return runPostScheduledTasks ( runner , 'tslint-fix' ) . toPromise ( ) . then ( ( ) => {
38
38
expect ( readFileContent ( 'projects/material/src/main.ts' ) )
39
- . toBe ( readFileContent ( expectedFixturePath ) ) ;
39
+ . toBe ( readFileContent ( expectedOutputPath ) ) ;
40
40
} ) ;
41
41
} ) ;
42
42
} ) ;
@@ -47,14 +47,15 @@ describe('update fixtures', () => {
47
47
}
48
48
49
49
/**
50
- * Creates a test app schematic tree that includes the specified fixture as TypeScript
51
- * entry point file.
50
+ * Creates a test app schematic tree that includes the specified test case as TypeScript
51
+ * entry point file. Also writes the app tree to a real file system location in order to be
52
+ * able to test the tslint fix rules.
52
53
*/
53
- function createTestAppWithFixture ( fixturePath : string ) {
54
+ function createTestAppWithTestCase ( testCaseInputPath : string ) {
54
55
const tempFileSystemHost = new TempScopedNodeJsSyncHost ( ) ;
55
56
const appTree = createTestApp ( ) ;
56
57
57
- appTree . overwrite ( '/projects/material/src/main.ts' , readFileContent ( fixturePath ) ) ;
58
+ appTree . overwrite ( '/projects/material/src/main.ts' , readFileContent ( testCaseInputPath ) ) ;
58
59
59
60
// Since the TSLint fix task expects all files to be present on the real file system, we
60
61
// map every file in the app tree to a temporary location on the file system.
0 commit comments