8000 fix: fixes for path mappings, tests, and coverage (#1359) · angular/angular-cli@860526c · GitHub
[go: up one dir, main page]

Skip to content

Commit 860526c

Browse files
TheLarkInnhansl
authored andcommitted
fix: fixes for path mappings, tests, and coverage (#1359)
* fix(): Multiple fixes for path mappings: * Removed invalid test case that was throwing path mappings tests because of a typescript bug. * Readded PathsPlugin for Path Mappings * Removed coverage preprocessor which was throwing bad type errors against ts code when it shouldn't be. * Added sourcemap support for istanbul instrumenter. Coverage files are still being generated. * fix: fix the way the build command runs for mobile tests * fix: fix the way the build command runs for mobile tests * fix: replaced promise based ng command with sh.exec to allow mappings test to run correctly against mobile * fix: replaced promise based ng command with sh.exec to allow mappings test to run correctly against mobile
1 parent 87b4cbd commit 860526c

File tree

8 files changed

+38
-46
lines changed

8 files changed

+38
-46
lines changed

addon/ng2/blueprints/ng2/files/__path__/test.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@ Promise.all([
2323
let testing = providers[0];
2424
let testingBrowser = providers[1];
2525

26-
testing.setBaseTestProviders(testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
27-
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
26+
testing.setBaseTestProviders(
27+
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
28+
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
29+
);
2830
});
2931

30-
let testContext = require.context('../src', true, /\.spec\.ts/);
31-
32-
/*
33-
* get all the files, for each file, call the context function
34-
* that will require the file and load it up here. Context will
35-
* loop and require those spec files here
36-
*/
37-
function requireAll(requireContext) {
32+
let testContext: any = require.context('../src', true, /\.spec\.ts/);
33+
function requireAll(requireContext: any) {
3834
return requireContext.keys().map(requireContext);
3935
}
4036

addon/ng2/blueprints/ng2/files/__path__/tsconfig.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@
1010
"rootDir": ".",
1111
"sourceMap": true,
1212
"target": "es5",
13-
"mapRoot": "/",
14-
"inlinesource": true
13+
"mapRoot": "/"
1514
},
1615
"compileOnSave": false,
1716
"buildOnSave": false,
18-
"exclude": [
19-
"node_modules",
20-
"bower_components"
21-
],
2217
"includes": [
2318
"**.d.ts"
2419
]

addon/ng2/models/webpack-build-common.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as webpack from 'webpack';
2-
import {LoaderConfig} from '../utilities/ts-path-mappings-webpack-plugin';
2+
import {LoaderConfig, PathsPlugin} from '../utilities/ts-path-mappings-webpack-plugin';
33

44
const path = require('path');
55
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
@@ -18,7 +18,10 @@ export function getWebpackCommonConfig(projectRoot: string) {
1818
resolve: {
1919
extensions: ['', '.ts', '.js'],
2020
root: path.resolve(projectRoot, './src'),
21-
moduleDirectories: ['node_modules']
21+
moduleDirectories: ['node_modules'],
22+
plugins: [
23+
new PathsPlugin(awesomeTypescriptLoaderConfig);
24+
]
2225
},
2326
context: path.resolve(__dirname, './'),
2427
entry: {

addon/ng2/models/webpack-build-test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export const getWebpackTestConfig = function(projectRoot: string) {
4444
query: {
4545
useWebpackText: true,
4646
tsconfig: path.resolve(projectRoot, './src/tsconfig.json'),
47-
// resolveGlobs: false,
4847
module: "commonjs",
4948
target: "es5",
5049
useForkChecker: true,
@@ -67,7 +66,7 @@ export const getWebpackTestConfig = function(projectRoot: string) {
6766
],
6867
postLoaders: [
6968
{
70-
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader',
69+
test: /\.(js|ts)$/, loader: 'sourcemap-istanbul-instrumenter-loader',
7170
exclude: [
7271
/\.(e2e|spec)\.ts$/,
7372
/node_modules/

addon/ng2/tasks/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = Task.extend({
3636

3737
// Single test entry file. Will run the test.ts bundle and track it.
3838
options.files = [{ pattern: './src/test.ts', watched: false }];
39-
options.preprocessors = { './src/test.ts': ['coverage','webpack','sourcemap'] };
39+
options.preprocessors = { './src/test.ts': ['webpack','sourcemap'] };
4040
options.webpack = webpackTestConfig(projectRoot);
4141
options.webpackMiddleware = {
4242
noInfo: true, // Hide webpack output because its noisy.

addon/ng2/utilities/ts-path-mappings-webpack-plugin.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ export class PathsPlugin implements ResolverPlugin {
183183
this.baseUrl
184184
);
185185

186-
console.log("CONFIG FILE AND BASE URL");
187-
console.log(this.configFilePath, this.absoluteBaseUrl);
188-
189186
this.mappings = [];
190187
let paths = this.options.paths || {};
191188
Object.keys(paths).forEach(alias => {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"shelljs": "^0.7.0",
8585
"silent-error": "^1.0.0",
8686
"source-map-loader": "^0.1.5",
87+
"sourcemap-istanbul-instrumenter-loader": "^0.2.0",
8788
"style-loader": "^0.13.1",
8889
"stylus": "^0.54.5",
8990
"stylus-loader": "^2.1.0",
@@ -97,7 +98,7 @@
9798
"typescript": "^2.0.0",
9899
"typings": "^0.8.1",
99100
"url-loader": "^0.5.7",
100-
"webpack": "2.1.0-beta.17",
101+
"webpack": "2.1.0-beta.18",
101102
"webpack-dev-server": "2.1.0-beta.0",
102103
"webpack-md5-hash": "0.0.5",
103104
"webpack-merge": "^0.14.0"

tests/e2e/e2e_workflow.spec.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('Basic end-to-end Workflow', function () {
4343
this.timeout(300000);
4444

4545
sh.exec('npm link', { silent: true });
46-
46+
4747
return tmp.setup('./tmp').then(function () {
4848
process.chdir('./tmp');
4949
expect(existsSync(path.join(process.cwd(), 'bin', 'ng')));
@@ -446,36 +446,37 @@ describe('Basic end-to-end Workflow', function () {
446446
});
447447
});
448448

449-
xit('Turn on path mapping in tsconfig.json and rebuild', function () {
449+
it('Turn on path mapping in tsconfig.json and rebuild', function () {
450450
this.timeout(420000);
451451

452452
const configFilePath = path.join(process.cwd(), 'src', 'tsconfig.json');
453453
let config = require(configFilePath);
454454

455455
config.compilerOptions.baseUrl = '';
456456

457-
// This should fail.
457+
// #TODO: When https://github.com/Microsoft/TypeScript/issues/9772 is fixed this should fail.
458458
config.compilerOptions.paths = { '@angular/*': [] };
459459
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8');
460460

461-
return ng(['build'])
462-
.catch(() => {
463-
return true;
464-
})
465-
.then((passed) => {
466-
expect(passed).to.equal(true);
467-
})
468-
.then(() => {
469-
// This should succeed.
470-
config.compilerOptions.paths = {
471-
'@angular/*': [ '*' ]
472-
};
473-
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8');
474-
})
475-
.then(() => ng(['build']))
476-
.catch(() => {
477-
expect('build failed where it should have succeeded').to.equal('');
478-
});
461+
sh.exec(`${ngBin} build`);
462+
// #TODO: Uncomment these lines when https://github.com/Microsoft/TypeScript/issues/9772 is fixed.
463+
// .catch(() => {
464+
// return true;
465+
// })
466+
// .then((passed) => {
467+
// expect(passed).to.equal(true);
468+
// })
469+
470+
// This should succeed.
471+
config.compilerOptions.paths = {
472+
'@angular/*': [ '../node_modules/@angular/*' ]
473+
};
474+
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2), 'utf8');
475+
sh.exec(`${ngBin} build`);
476+
477+
expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true);
478+
const indexHtml = fs.readFileSync(path.join(process.cwd(), 'dist/index.html'), 'utf-8');
479+
expect(indexHtml).to.include('main.bundle.js');
479480
});
480481

481482
it('Serve and run e2e tests after all other commands', function () {

0 commit comments

Comments
 (0)
0