parent
396766104b
commit
cdb0215d0b
|
@ -6,125 +6,73 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as fs from 'fs';
|
import {join} from 'path';
|
||||||
import * as path from 'path';
|
|
||||||
import {cat, find} from 'shelljs';
|
|
||||||
|
|
||||||
import {mainNgcc} from '../../src/ngcc/src/main';
|
import {mainNgcc} from '../../src/ngcc/src/main';
|
||||||
|
|
||||||
import {TestSupport, isInBazel, setup} from '../test_support';
|
import {TestSupport, isInBazel, setup} from '../test_support';
|
||||||
|
|
||||||
function setupNodeModules(support: TestSupport): void {
|
|
||||||
const corePath = path.join(process.env.TEST_SRCDIR, 'angular/packages/core/npm_package');
|
|
||||||
const commonPath = path.join(process.env.TEST_SRCDIR, 'angular/packages/common/npm_package');
|
|
||||||
|
|
||||||
const nodeModulesPath = path.join(support.basePath, 'node_modules');
|
|
||||||
const angularCoreDirectory = path.join(nodeModulesPath, '@angular/core');
|
|
||||||
const angularCommonDirectory = path.join(nodeModulesPath, '@angular/common');
|
|
||||||
|
|
||||||
// fs.symlinkSync(corePath, angularCoreDirectory);
|
|
||||||
// fs.symlinkSync(commonPath, angularCommonDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('ngcc behavioral tests', () => {
|
describe('ngcc behavioral tests', () => {
|
||||||
if (!isInBazel()) {
|
if (!isInBazel()) {
|
||||||
// These tests should be excluded from the non-Bazel build.
|
// These tests should be excluded from the non-Bazel build.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let basePath: string;
|
// Temporary local debugging aid. Set to `true` to turn on.
|
||||||
let outDir: string;
|
const preserveOutput = false;
|
||||||
let write: (fileName: string, content: string) => void;
|
const onSpecCompleted = (format: string) => {
|
||||||
let errorSpy: jasmine.Spy&((s: string) => void);
|
if (preserveOutput) {
|
||||||
|
const {tmpdir} = require('os');
|
||||||
|
const {cp, mkdir, rm, set} = require('shelljs');
|
||||||
|
|
||||||
function shouldExist(fileName: string) {
|
const tempRootDir = join(tmpdir(), 'ngcc-spec', format);
|
||||||
if (!fs.existsSync(path.resolve(outDir, fileName))) {
|
const outputDir = 'node_modules_ngtsc';
|
||||||
throw new Error(`Expected ${fileName} to be emitted (outDir: ${outDir})`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldNotExist(fileName: string) {
|
set('-e');
|
||||||
if (fs.existsSync(path.resolve(outDir, fileName))) {
|
rm('-rf', tempRootDir);
|
||||||
throw new Error(`Did not expect ${fileName} to be emitted (outDir: ${outDir})`);
|
mkdir('-p', tempRootDir);
|
||||||
}
|
cp('-R', join(support.basePath, outputDir), tempRootDir);
|
||||||
}
|
|
||||||
|
|
||||||
function getContents(fileName: string): string {
|
global.console.log(`Copied '${outputDir}' to '${tempRootDir}'.`);
|
||||||
shouldExist(fileName);
|
|
||||||
const modulePath = path.resolve(outDir, fileName);
|
|
||||||
return fs.readFileSync(modulePath, 'utf8');
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function writeConfig(
|
let support: TestSupport;
|
||||||
tsconfig: string =
|
beforeEach(() => support = setup());
|
||||||
'{"extends": "./tsconfig-base.json", "angularCompilerOptions": {"enableIvy": "ngtsc"}}') {
|
|
||||||
write('tsconfig.json', tsconfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
errorSpy = jasmine.createSpy('consoleError').and.callFake(console.error);
|
|
||||||
const support = setup();
|
|
||||||
basePath = support.basePath;
|
|
||||||
outDir = path.join(basePath, 'built');
|
|
||||||
process.chdir(basePath);
|
|
||||||
write = (fileName: string, content: string) => { support.write(fileName, content); };
|
|
||||||
|
|
||||||
setupNodeModules(support);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should run ngcc without errors for fesm2015', () => {
|
it('should run ngcc without errors for fesm2015', () => {
|
||||||
const nodeModulesPath = path.join(basePath, 'node_modules');
|
const commonPath = join(support.basePath, 'node_modules/@angular/common');
|
||||||
console.error(nodeModulesPath);
|
const format = 'fesm2015';
|
||||||
const commonPath = path.join(nodeModulesPath, '@angular/common');
|
|
||||||
const exitCode = mainNgcc([commonPath, 'fesm2015']);
|
|
||||||
|
|
||||||
console.warn(find('node_modules_ngtsc').filter(p => p.endsWith('.js') || p.endsWith('map')));
|
expect(mainNgcc([commonPath, format])).toBe(0);
|
||||||
|
|
||||||
console.warn(cat('node_modules_ngtsc/@angular/common/fesm2015/common.js').stdout);
|
onSpecCompleted(format);
|
||||||
console.warn(cat('node_modules_ngtsc/@angular/common/fesm2015/common.js.map').stdout);
|
|
||||||
|
|
||||||
expect(exitCode).toBe(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run ngcc without errors for fesm5', () => {
|
it('should run ngcc without errors for fesm5', () => {
|
||||||
const nodeModulesPath = path.join(basePath, 'node_modules');
|
const commonPath = join(support.basePath, 'node_modules/@angular/common');
|
||||||
console.error(nodeModulesPath);
|
const format = 'fesm5';
|
||||||
const commonPath = path.join(nodeModulesPath, '@angular/common');
|
|
||||||
const exitCode = mainNgcc([commonPath, 'fesm5']);
|
|
||||||
|
|
||||||
console.warn(find('node_modules_ngtsc').filter(p => p.endsWith('.js') || p.endsWith('map')));
|
expect(mainNgcc([commonPath, format])).toBe(0);
|
||||||
|
|
||||||
console.warn(cat('node_modules_ngtsc/@angular/common/fesm5/common.js').stdout);
|
onSpecCompleted(format);
|
||||||
console.warn(cat('node_modules_ngtsc/@angular/common/fesm5/common.js.map').stdout);
|
|
||||||
|
|
||||||
expect(exitCode).toBe(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run ngcc without errors for esm2015', () => {
|
it('should run ngcc without errors for esm2015', () => {
|
||||||
const nodeModulesPath = path.join(basePath, 'node_modules');
|
const commonPath = join(support.basePath, 'node_modules/@angular/common');
|
||||||
console.error(nodeModulesPath);
|
const format = 'esm2015';
|
||||||
const commonPath = path.join(nodeModulesPath, '@angular/common');
|
|
||||||
const exitCode = mainNgcc([commonPath, 'esm2015']);
|
|
||||||
|
|
||||||
console.warn(find('node_modules_ngtsc').filter(p => p.endsWith('.js') || p.endsWith('map')));
|
expect(mainNgcc([commonPath, format])).toBe(0);
|
||||||
|
|
||||||
console.warn(cat('node_modules_ngtsc/@angular/common/esm2015/src/directives/ng_if.js').stdout);
|
onSpecCompleted(format);
|
||||||
console.warn(cat('node_modules_ngtsc/@angular/common/esm2015/http/src/module.js').stdout);
|
|
||||||
|
|
||||||
expect(exitCode).toBe(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should run ngcc without errors for esm5', () => {
|
it('should run ngcc without errors for esm5', () => {
|
||||||
const nodeModulesPath = path.join(basePath, 'node_modules');
|
const commonPath = join(support.basePath, 'node_modules/@angular/common');
|
||||||
console.error(nodeModulesPath);
|
const format = 'esm5';
|
||||||
const commonPath = path.join(nodeModulesPath, '@angular/common');
|
|
||||||
const exitCode = mainNgcc([commonPath, 'esm5']);
|
|
||||||
|
|
||||||
console.warn(find('node_modules_ngtsc').filter(p => p.endsWith('.js') || p.endsWith('map')));
|
expect(mainNgcc([commonPath, format])).toBe(0);
|
||||||
|
|
||||||
console.warn(cat('node_modules_ngtsc/@angular/common/esm5/src/directives/ng_if.js').stdout);
|
onSpecCompleted(format);
|
||||||
console.warn(cat('node_modules_ngtsc/@angular/common/esm5/http/src/module.js').stdout);
|
|
||||||
|
|
||||||
expect(exitCode).toBe(0);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue