Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
},
"schematics": "./src/collection.json",
"dependencies": {
"@angular-devkit/core": "~7.3.9",
"@angular-devkit/schematics": "~7.3.9",
"@angular-devkit/core": "~8.0.0",
"@angular-devkit/schematics": "~8.0.0",
"@nativescript/tslint-rules": "~0.0.1",
"@phenomnomnominal/tsquery": "^3.0.0",
"@schematics/angular": "~7.3.9",
"@schematics/angular": "~8.0.0",
"tslint": "^5.16.0"
},
"devDependencies": {
Expand All @@ -28,7 +28,7 @@
"conventional-changelog-cli": "^2.0.1",
"jasmine": "^2.8.0",
"jasmine-spec-reporter": "^4.2.1",
"typescript": "3.2.4"
"typescript": "3.4.5"
},
"repository": {
"type": "git",
Expand Down
4 changes: 1 addition & 3 deletions src/add-ns/_ns-files/__sourceDir__/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
"android": {
"v8Flags": "--expose_gc"
},
"main": "<%= main %><%= nsext %>.js",
"name": "migration-ng",
"version": "4.1.0"
"main": "<%= main %><%= nsext %>.js"
}
17 changes: 11 additions & 6 deletions src/add-ns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,18 @@ const modifyWebTsconfig = (tree: Tree, context: SchematicContext) => {
const tsConfigPath = projectSettings.tsConfig;
const tsConfig: any = getJsonFile(tree, tsConfigPath);

const srcDir = projectSettings.sourceRoot;

// files
const defaultFiles = ["main.ts", "polyfills.ts"];
const defaultFiles = [
`${srcDir}/main.ts`,
`${srcDir}/polyfills.ts`,
];

tsConfig.files = tsConfig.files || [];
tsConfig.files.push(...defaultFiles);

// paths
const srcDir = projectSettings.sourceRoot;
const webPaths = {
"@src/*": [
`${srcDir}/*.web`,
Expand Down Expand Up @@ -302,16 +307,16 @@ const addDependencies = () => (tree: Tree, context: SchematicContext) => {

// @UPGRADE: Update all versions whenever {N} version updates
const depsToAdd = {
'nativescript-angular': '~7.2.0',
'nativescript-angular': '~8.0.1',
'nativescript-theme-core': '~1.0.4',
'reflect-metadata': '~0.1.12',
'tns-core-modules': '~5.2.0'
'tns-core-modules': '~5.4.0'
};
packageJson.dependencies = Object.assign({}, depsToAdd, packageJson.dependencies);

const devDepsToAdd = {
'nativescript-dev-webpack': '^0.20.0',
'@nativescript/schematics': '~0.4.0',
'nativescript-dev-webpack': '~0.24.0',
'@nativescript/schematics': '~0.6.0',
};
packageJson.devDependencies = Object.assign({}, devDepsToAdd, packageJson.devDependencies);

Expand Down
39 changes: 20 additions & 19 deletions src/add-ns/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ describe('Add {N} schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
beforeEach(async () => {
appTree = new UnitTestTree(new HostTree);
appTree = setupProject(appTree, schematicRunner, project);
appTree = await setupProject(appTree, schematicRunner, project);
});

describe('when using the default options', () => {
beforeEach(() => {
appTree = schematicRunner.runSchematic('add-ns', defaultOptions, appTree);
beforeEach(async () => {
appTree = await schematicRunner.runSchematicAsync('add-ns', defaultOptions, appTree)
.toPromise();
});

it('should add dependency to NativeScript schematics', () => {
Expand Down Expand Up @@ -107,16 +108,16 @@ describe('Add {N} schematic', () => {
expect(nativescript['id']).toEqual('org.nativescript.ngsample');
});

it('should modify the tsconfig.app.json(web) to include files and path mappings', () => {
const webTsConfigPath = '/src/tsconfig.app.json';
it('should modify the tsconfig.app.json (web) to include files and path mappings', () => {
const webTsConfigPath = '/tsconfig.app.json';
expect(appTree.files).toContain(webTsConfigPath);

const webTsconfig = JSON.parse(getFileContent(appTree, webTsConfigPath));
const files = webTsconfig.files;

expect(files).toBeDefined();
expect(files.includes('main.ts')).toBeTruthy();
expect(files.includes('polyfills.ts')).toBeTruthy();
expect(files.includes('src/main.ts')).toBeTruthy();
expect(files.includes('src/polyfills.ts')).toBeTruthy();

const paths = webTsconfig.compilerOptions.paths;
expect(paths).toBeDefined();
Expand Down Expand Up @@ -148,7 +149,7 @@ describe('Add {N} schematic', () => {
expect(maps).toContain("src/*.ts");
});

it('should modify the base tsconfig.app.json to include path mappings', () => {
it('should modify the base tsconfig.json to include path mappings', () => {
const baseTsConfigPath = '/tsconfig.json';
expect(appTree.files).toContain(baseTsConfigPath);

Expand Down Expand Up @@ -186,13 +187,13 @@ describe('Add {N} schematic', () => {
});

describe('when the skipAutoGeneratedComponent flag is raised', () => {
beforeEach(() => {
beforeEach(async () => {
const options = {
...defaultOptions,
skipAutoGeneratedComponent: true,
};

appTree = schematicRunner.runSchematic('add-ns', options, appTree);
appTree = await schematicRunner.runSchematicAsync('add-ns', options, appTree).toPromise();
});

it('should not add a sample shared component', () => {
Expand All @@ -215,13 +216,13 @@ describe('Add {N} schematic', () => {
});

describe('when the sample flag is raised', () => {
beforeEach(() => {
beforeEach(async () => {
const options = {
...defaultOptions,
sample: true,
};

appTree = schematicRunner.runSchematic('add-ns', options, appTree);
appTree = await schematicRunner.runSchematicAsync('add-ns', options, appTree).toPromise();
});

it('should generate sample files', () => {
Expand Down Expand Up @@ -251,31 +252,31 @@ describe('Add {N} schematic', () => {
});
});

function setupProject(
async function setupProject(
tree: UnitTestTree,
schematicRunner: SchematicTestRunner,
name: string,
) {

tree = schematicRunner.runExternalSchematic(
tree = await schematicRunner.runExternalSchematicAsync(
'@schematics/angular',
'workspace',
{
name: 'workspace',
version: '7.0.0',
version: '8.0.0',
newProjectRoot: ''
}
);
).toPromise();

tree = schematicRunner.runExternalSchematic(
tree = await schematicRunner.runExternalSchematicAsync(
'@schematics/angular',
'application',
{
name,
projectRoot: ''
},
tree
);
).toPromise();

return tree;
}
16 changes: 8 additions & 8 deletions src/angular-json/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe('Angular JSON Config Schematic', () => {

describe('with default options (name only)', () => {
let tree: UnitTestTree;
beforeAll(() => {
tree = schematicRunner.runSchematic('angular-json', defaultOptions);
beforeAll(async () => {
tree = await schematicRunner.runSchematicAsync('angular-json', defaultOptions).toPromise();
})

it('should create angular.json files', () => {
Expand All @@ -35,24 +35,24 @@ describe('Angular JSON Config Schematic', () => {
});
})

it('should insert the prefix option', () => {
it('should insert the prefix option', async () => {
const prefix = 'custom-prefix';
const tree = schematicRunner.runSchematic('angular-json', { ...defaultOptions, prefix });
const tree = await schematicRunner.runSchematicAsync('angular-json', { ...defaultOptions, prefix }).toPromise();
expect(getFileContent(tree, configPath)).toContain(`"prefix": "${prefix}"`);
});

it('should insert the sourceRoot option', () => {
it('should insert the sourceRoot option', async () => {
const sourceRoot = 'src';
const tree = schematicRunner.runSchematic('angular-json', { ...defaultOptions, sourceRoot });
const tree = await schematicRunner.runSchematicAsync('angular-json', { ...defaultOptions, sourceRoot }).toPromise();
expect(getFileContent(tree, configPath)).toContain(`"sourceRoot": "${sourceRoot}"`);
});

it('should create files inside path when specified', () => {
it('should create files inside path when specified', async () => {
const path = '/path/to/my/app';
const appJsonPath = `${path}/angular.json`;
const options = { ...defaultOptions, path };

const tree = schematicRunner.runSchematic('angular-json', options);
const tree = await schematicRunner.runSchematicAsync('angular-json', options).toPromise();
expect(tree.files).toContain(appJsonPath);
});
});
36 changes: 18 additions & 18 deletions src/convert-relative-imports/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ describe('Convert relative imports to mapped imports', () => {
join(__dirname, '../collection.json')
);

it('should convert the relative imports in a newly generated file', () => {
it('should convert the relative imports in a newly generated file', async () => {
let appTree = createTestProject(projSetup);

appTree.create(aboutModulePath, relativeImportContent);
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
const actual = getFileContent(appTree, aboutModulePath);

expect(actual).toEqual(fixedImportContent);
});

it('should convert the relative imports in a modified file', () => {
it('should convert the relative imports in a modified file', async () => {
const existingContent = `
import { AboutComponent } from '${importPrefix}/about/about.component';
`;
Expand All @@ -60,85 +60,85 @@ describe('Convert relative imports to mapped imports', () => {
}]);

appTree.overwrite(aboutModulePath, modifiedContent);
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
const actual = getFileContent(appTree, aboutModulePath);

expect(actual).toEqual(expected);
});

it('should convert the relative imports in a created and then renamed file', () => {
it('should convert the relative imports in a created and then renamed file', async () => {
let appTree = createTestProject(projSetup);

const renamedFilePath = aboutModulePath.replace(".ts", ".tns.ts");

appTree.create(aboutModulePath, relativeImportContent);
appTree.rename(aboutModulePath, renamedFilePath);

appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
const actual = getFileContent(appTree, renamedFilePath);

expect(actual).toEqual(fixedImportContent);
});

it('should not modify files that weren\'t modified', () => {
it('should not modify files that weren\'t modified', async () => {
let appTree = createTestProject(projSetup, [{
path: aboutModulePath,
content: relativeImportContent
}]);

appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
const actual = getFileContent(appTree, aboutModulePath);

expect(actual).toEqual(relativeImportContent);
});

it('should not modify files with extension other than .ts', () => {
it('should not modify files with extension other than .ts', async () => {
let appTree = createTestProject(projSetup);

const generatedFilePath = `${sourceDirectory}/about/about.component.tsx`;

appTree.create(generatedFilePath, relativeImportContent);
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();
const actual = getFileContent(appTree, generatedFilePath);

expect(actual).toEqual(relativeImportContent);
});

it('should not modify files specified as ignored in the invocation options', () => {
it('should not modify files specified as ignored in the invocation options', async () => {
let appTree = createTestProject(projSetup);

appTree.create(aboutModulePath, relativeImportContent);

const options: ConvertRelativeImportsOptions = { ...defaultOptions, filesToIgnore: [aboutModulePath] };
appTree = schematicRunner.runSchematic('convert-relative-imports', options, appTree);
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', options, appTree).toPromise();
const actual = getFileContent(appTree, aboutModulePath);

expect(actual).toEqual(relativeImportContent);
});

it('should not modify files that are deleted by previous rules', () => {
it('should not modify files that are deleted by previous rules', async () => {
let appTree = createTestProject(projSetup, [{
path: aboutModulePath,
content: relativeImportContent
}]);

appTree.delete(aboutModulePath);
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();

expect(appTree.get(aboutModulePath)).toBeNull();
});

it('should not modify files that were created and then deleted by previous rules', () => {
it('should not modify files that were created and then deleted by previous rules', async () => {
let appTree = createTestProject(projSetup);

appTree.create(aboutModulePath, relativeImportContent);
appTree.delete(aboutModulePath);
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();

expect(appTree.get(aboutModulePath)).toBeNull();
});

it('should not modify files that were modified and then deleted by previous rules', () => {
it('should not modify files that were modified and then deleted by previous rules', async () => {

let appTree = createTestProject(projSetup, [{
path: aboutModulePath,
Expand All @@ -147,7 +147,7 @@ describe('Convert relative imports to mapped imports', () => {

appTree.overwrite(aboutModulePath, relativeImportContent + '\nconsole.log(\'modified\');\n');
appTree.delete(aboutModulePath);
appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree);
appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise();

expect(appTree.get(aboutModulePath)).toBeNull();
});
Expand Down
Loading