Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit c4d918b

Browse files
committed
tests: fix
1 parent e4498df commit c4d918b

16 files changed

+67
-42
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [ "es2015" ]
3+
}

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ sudo: false
22
language: node_js
33
before_script:
44
- npm run build
5+
- npm run build:babel
56
node_js:
6-
- "4"
77
- "6"

package.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
"main": "dist/entry.js",
66
"scripts": {
77
"prepublish": "npm run build",
8-
"pretest": "npm run build",
9-
"test": "mocha dist/test",
8+
"test": "mocha dist.babel/test",
109
"watch": "npm run watch:ts",
1110
"watch:ts": "npm run build:ts -- --watch --diagnostics",
11+
"watch:babel": "babel dist --watch --out-dir dist.babel",
1212
"prebuild": "npm run lint",
1313
"build": "npm run build:ts",
1414
"build:ts": "tsc -p src --pretty",
15+
"build:babel": "babel dist --out-dir dist.babel",
1516
"lint": "tslint src/*.ts"
1617
},
1718
"author": "Stanislav Panferov <[email protected]> (http://panferov.me/)",
@@ -39,6 +40,10 @@
3940
"source-map-support": "^0.4.0"
4041
},
4142
"devDependencies": {
43+
"babel-cli": "^6.10.1",
44+
"babel-core": "^6.10.4",
45+
"babel-preset-es2015": "^6.9.0",
46+
"bluebird": "^3.4.1",
4247
"chai": "^3.5.0",
4348
"git-hooks": "^1.0.2",
4449
"grunt": "^1.0.1",
@@ -56,8 +61,8 @@
5661
"rimraf": "^2.5.0",
5762
"sinon": "^1.17.4",
5863
"temp": "^0.8.3",
59-
"tslint": "3.11.0-dev.0",
60-
"typescript": "^1.9.0-dev.20160625-1.0",
64+
"tslint": "^3.13.0-dev.0",
65+
"typescript": "^2.0.0-dev.20160706",
6166
"webpack": "2.1.0-beta.4"
6267
}
6368
}

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function transform(webpack: IWebPack, instance: ICompilerInstance, fileName: str
144144
let resultSourceMap = null;
145145
let state = instance.tsState;
146146

147-
let useSlowEmit = state.compilerConfig.options.declaration || state.loaderConfig.disableFastEmit
147+
let useSlowEmit = state.compilerConfig.options.declaration || state.loaderConfig.disableFastEmit;
148148
if (useSlowEmit) {
149149
let output = state.emit(fileName);
150150
let result = helpers.findResultFor(output, fileName);

src/instance.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface LoaderConfig {
6969
emitRequireType?: boolean;
7070
reEmitDependentFiles?: boolean;
7171
tsconfig?: string;
72+
tsconfigContent?: string;
7273
useWebpackText?: boolean;
7374
externals?: string[];
7475
doTypeCheck?: boolean;
@@ -306,13 +307,13 @@ export function readConfigFile(baseDir: string, query: QueryOptions, tsImpl: typ
306307
configFilePath = tsImpl.findConfigFile(process.cwd(), tsImpl.sys.fileExists);
307308
}
308309

309-
let existingOptions = tsImpl.convertCompilerOptionsFromJson(query, process.cwd(), 'atl.query');
310+
let existingOptions = tsImpl.convertCompilerOptionsFromJson(query, process.cwd(), 'atl.query');
310311

311-
if (!configFilePath) {
312+
if (!configFilePath || query.tsconfigContent) {
312313
return {
313-
configFilePath: process.cwd(),
314+
configFilePath: configFilePath || process.cwd(),
314315
compilerConfig: tsImpl.parseJsonConfigFileContent(
315-
{},
316+
query.tsconfigContent || {},
316317
tsImpl.sys,
317318
process.cwd(),
318319
_.extend({}, tsImpl.getDefaultCompilerOptions(), existingOptions.options) as ts.CompilerOptions,

src/paths-plugin.ts

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ export class PathsPlugin implements ResolverPlugin {
106106
resolver.apply(new ModulesInRootPlugin("module", this.absoluteBaseUrl, "resolve"));
107107
}
108108

109-
110109
mappings.forEach(mapping => {
111110
resolver.plugin(this.source, this.createPlugin(resolver, mapping));
112111
});

src/test/fixtures/salsa/exclude/ignored.js

-8
This file was deleted.

src/test/fixtures/salsa/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { sum } from './lib';
2+
3+
sum('asdf', /asdf/);

src/test/fixtures/salsa/index.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import { sum } from './lib';
2-
import { mul } from './exclude/ignored';
32

43
sum('asdf', /asdf/);
5-
6-
// should be any
7-
mul('asdf', /asdf/);

src/test/fixtures/salsa/tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
"allowJs": true
66
},
77
"exclude": [
8-
"exclude",
9-
"node_modules",
10-
"bower_components"
8+
"*"
119
]
1210
}

src/test/fixtures/tsx/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"experimentalAsyncFunctions": true
1414
},
1515
"exclude": [
16-
"node_modules",
17-
"bower_components"
16+
"*"
1817
]
1918
}

src/test/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('main test', function() {
4545
entry: fixturePath(['tsx', 'basic.tsx'])
4646
};
4747

48-
let loaderQuery = { tsconfig };
48+
let loaderQuery = { tsconfig, tsconfigContent: null };
4949

5050
let stats = await cleanAndCompile(createConfig(config, { loaderQuery }));
5151
expect(stats.compilation.errors.length).eq(1);

src/test/salsa.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@ import {
44
} from './utils';
55

66
describe('salsa test', function() {
7-
it('should compile js file', async function() {
7+
it('should compile ts file with js invoke', async function() {
88
let config = {
99
entry: fixturePath(['salsa', 'index.ts'])
1010
};
1111

1212
let tsconfig = fixturePath(['salsa', 'tsconfig.json']);
13-
let loaderQuery = { tsconfig };
14-
let exclude = [ /exclude/ ];
13+
let loaderQuery = { tsconfig, tsconfigContent: null };
1514

16-
let stats = await cleanAndCompile(createConfig(config, { loaderQuery, exclude }));
15+
let stats = await cleanAndCompile(createConfig(config, { loaderQuery }));
16+
console.log(stats.compilation.errors)
17+
expect(stats.compilation.errors.length).eq(1);
18+
});
1719

18-
console.log(stats.compilation.errors);
20+
xit('should compile js file as entry point', async function() {
21+
let config = {
22+
entry: fixturePath(['salsa', 'index.js'])
23+
};
24+
25+
let tsconfig = fixturePath(['salsa', 'tsconfig.json']);
26+
let loaderQuery = { tsconfig, tsconfigContent: null };
1927

20-
expect(stats.compilation.errors.length).eq(2);
21-
expect(stats.compilation.errors[0].toString()).include('Cannot find module');
22-
expect(stats.compilation.errors[1].toString()).include(`Argument of type 'string'`);
28+
let stats = await cleanAndCompile(createConfig(config, { loaderQuery }));
29+
console.log(stats.compilation.errors)
30+
expect(stats.compilation.errors.length).eq(1);
2331
});
2432
});

src/test/tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"moduleResolution": "node",
5+
"sourceMap": true,
6+
"lib": [ "es6", "dom" ]
7+
},
8+
"exclude": [
9+
"*"
10+
]
11+
}

src/test/utils.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as fs from 'fs';
33
import * as _ from 'lodash';
44

55
const temp = require('temp').track();
6-
76
require('babel-polyfill');
87
require('source-map-support').install();
98

@@ -52,19 +51,31 @@ export function createConfig(conf, _options: ConfigOptions = defaultOptions) {
5251
{
5352
test: /\.(tsx?|jsx?)/,
5453
loader: loaderDir,
55-
query: Object.assign({ target: 'es6' }, options.loaderQuery)
54+
query: Object.assign(
55+
{
56+
target: 'es6',
57+
},
58+
{
59+
tsconfigContent: {
60+
exclude: ["*"]
61+
}
62+
},
63+
options.loaderQuery
64+
)
5665
},
5766
],
5867
},
5968
plugins: []
6069
};
6170

71+
let loader = defaultConfig.module.loaders[0] as any;
72+
6273
if (options.include) {
63-
(defaultConfig.module.loaders[0] as any).include = options.include;
74+
loader.include = (loader.include || []).concat(options.include);
6475
}
6576

6677
if (options.exclude) {
67-
(defaultConfig.module.loaders[0] as any).exclude = options.exclude;
78+
loader.exclude = (loader.exclude || []).concat(options.exclude);
6879
}
6980

7081
if (options.watch) {

src/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
},
1515
"compileOnSave": false,
1616
"exclude": [
17-
"test",
1817
"test/fixtures",
1918
"test/output/*"
2019
]

0 commit comments

Comments
 (0)