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

Commit 1436114

Browse files
committed
feat: refactor tests, fix #349, #323, #335
1 parent 6bd83ff commit 1436114

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+939
-5075
lines changed

.babelrc

-3
This file was deleted.

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ src/test/output
1010
.vagrant
1111
Vagrantfile
1212
issues
13-
.idea
13+
.idea
14+
.test

.node-version

-1
This file was deleted.

.travis.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
sudo: false
22
language: node_js
3+
before_install:
4+
- curl -o- -L https://yarnpkg.com/install.sh | bash
5+
- export PATH=$HOME/.yarn/bin:$PATH
36
before_script:
4-
- npm i
5-
- npm run compile
7+
- yarn i
8+
- yarn run build
69
node_js:
710
- "7"

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var loader = require('./dist');
2+
3+
module.exports = loader;

package.json

+17-19
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
"typings": "./dist/index.d.ts",
77
"scripts": {
88
"prepublish": "npm run build",
9-
"test": "mocha dist/test --harmony-async-await",
109
"watch": "npm run watch:ts",
1110
"watch:ts": "npm run build:ts -- --watch --diagnostics",
1211
"prebuild": "npm run lint",
1312
"compile": "tsc --pretty",
14-
"build": "rm -rf dist && tsc -p prod --pretty",
13+
"build": "rm -rf dist && tsc --pretty",
1514
"lint": "tslint src/*.ts",
16-
"release": "standard-version"
15+
"release": "standard-version",
16+
"test": "mocha --timeout 10000 dist/__test__"
1717
},
1818
"author": "Stanislav Panferov <[email protected]> (http://panferov.me/)",
1919
"repository": {
@@ -33,34 +33,32 @@
3333
"homepage": "https://github.com/s-panferov/awesome-typescript-loader",
3434
"dependencies": {
3535
"colors": "^1.1.2",
36-
"enhanced-resolve": "^2.3.0",
36+
"enhanced-resolve": "^3.0.3",
3737
"loader-utils": "^0.2.16",
38-
"lodash": "^4.13.1",
39-
"object-assign": "^4.1.0",
40-
"source-map-support": "^0.4.0"
38+
"lodash": "^4.17.4",
39+
"object-assign": "^4.1.1",
40+
"source-map-support": "^0.4.11"
4141
},
4242
"devDependencies": {
4343
"@types/chai": "^3.4.34",
44-
"@types/colors": "^0.6.33",
45-
"@types/lodash": "^4.14.43",
46-
"@types/mocha": "^2.2.32",
47-
"@types/node": "^6.0.46",
48-
"@types/sinon": "^1.16.31",
49-
"babel-core": "^6.20.0",
50-
"babel-preset-es2015": "^6.18.0",
51-
"bluebird": "^3.4.1",
44+
"@types/colors": "^1.1.1",
45+
"@types/lodash": "^4.14.51",
46+
"@types/mocha": "^2.2.38",
47+
"@types/node": "^7.0.4",
48+
"@types/sinon": "^1.16.34",
49+
"bluebird": "^3.4.7",
5250
"chai": "^3.5.0",
5351
"empty-module": "0.0.2",
52+
"fs-extra": "^2.0.0",
5453
"git-hooks": "^1.0.2",
5554
"mkdirp": "^0.5.1",
5655
"mocha": "^3.2.0",
5756
"ps-node": "^0.1.1",
5857
"rimraf": "^2.5.0",
59-
"sinon": "^1.17.4",
6058
"standard-version": "^4.0.0",
6159
"temp": "^0.8.3",
62-
"tslint": "^4.0.2",
63-
"typescript": "^2.1.4",
64-
"webpack": "2.1.0-beta.25"
60+
"tslint": "^4.4.2",
61+
"typescript": "^2.1.5",
62+
"webpack": "2.2.0"
6563
}
6664
}

src/__test__/babel.ts

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import {
2+
clear, src, webpackConfig, tsconfig, install,
3+
watch, checkOutput, expectErrors, query, run
4+
} from './utils';
5+
6+
run(__filename, async function() {
7+
clear();
8+
const index = src('index.ts', `
9+
class HiThere {
10+
constructor(a: number, b: string) {
11+
const t = a + b;
12+
}
13+
}
14+
`);
15+
16+
install('babel-core', 'babel-preset-es2015');
17+
tsconfig();
18+
19+
const watcher = await watch(webpackConfig(query({
20+
useBabel: true,
21+
babelOptions: {
22+
"presets": ["es2015"]
23+
}
24+
})));
25+
26+
await watcher.wait();
27+
28+
expectErrors(0);
29+
checkOutput('index.js', `
30+
var HiThere = function HiThere(a, b) {
31+
_classCallCheck(this, HiThere);
32+
var t = a + b;
33+
}
34+
`);
35+
36+
index.update(() => `
37+
function sum(...items: number[]) {
38+
return items.reduce((a,b) => a + b, 0);
39+
}
40+
`);
41+
42+
await watcher.wait();
43+
44+
expectErrors(0);
45+
checkOutput('index.js', `
46+
function sum() {
47+
for(var _len = arguments.length,
48+
items = Array(_len),
49+
_key = 0;
50+
_key < _len;
51+
_key++
52+
) {
53+
items[_key] = arguments[_key];
54+
}
55+
return items.reduce(function(a,b){ return a + b; }, 0);
56+
}
57+
`);
58+
});

src/__test__/declaration.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
clear, src, webpackConfig, tsconfig,
3+
watch, checkOutput, expectErrors, run
4+
} from './utils';
5+
6+
run(__filename, async function() {
7+
clear();
8+
const index = src('index.ts', `
9+
export { default as sum } from './utils/sum'
10+
`);
11+
12+
src('utils/sum.ts', `
13+
export default function sum(a: number, b: number) {
14+
return a + b;
15+
}
16+
`);
17+
18+
tsconfig({
19+
declaration: true
20+
});
21+
22+
const watcher = watch(webpackConfig());
23+
24+
await watcher.wait();
25+
26+
expectErrors(0);
27+
28+
checkOutput('src/index.d.ts', `
29+
export { default as sum } from './utils/sum'
30+
`);
31+
32+
checkOutput('src/utils/sum.d.ts', `
33+
export default function sum(a: number, b: number): number
34+
`);
35+
36+
src('utils/mul.ts', `
37+
export default function mul(a: number, b: number) {
38+
return a * b;
39+
}
40+
`);
41+
42+
index.update(() => `
43+
export { default as sum } from './utils/sum'
44+
export { default as mul } from './utils/mul'
45+
`);
46+
47+
await watcher.wait();
48+
49+
checkOutput('src/utils/mul.d.ts', `
50+
export default function mul(a: number, b: number): number
51+
`);
52+
53+
checkOutput('src/index.d.ts', `
54+
export { default as sum } from './utils/sum';
55+
export { default as mul } from './utils/mul';
56+
`);
57+
});

src/__test__/error.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {
2+
clear, src, webpackConfig, tsconfig,
3+
compile, checkOutput, expectErrors, run
4+
} from './utils';
5+
6+
run(__filename, async function() {
7+
clear();
8+
src('index.ts', `
9+
function sum(a: number, b: number) {
10+
return a + b;
11+
}
12+
13+
sum('test', 1);
14+
`);
15+
16+
tsconfig();
17+
18+
await compile(webpackConfig());
19+
20+
expectErrors(1, [
21+
`Argument of type '"test"' is not assignable to parameter of type 'number'`
22+
]);
23+
24+
checkOutput('index.js', `
25+
function sum(a, b) {
26+
return a + b;
27+
}
28+
29+
sum('test', 1);
30+
`);
31+
});

src/__test__/react.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
clear, src, webpackConfig, expectErrors,
3+
tsconfig, compile, install, entry, run
4+
} from './utils';
5+
6+
run(__filename, async function() {
7+
clear();
8+
install(
9+
'react',
10+
'react-dom',
11+
'@types/react',
12+
'@types/react-dom'
13+
);
14+
15+
src('index.tsx', `
16+
import * as React from 'react'
17+
import * as ReactDOM from 'react-dom'
18+
import App from './app'
19+
ReactDOM.render(<App title='Test' />, document.body)
20+
`);
21+
22+
src('app.tsx', `
23+
import * as React from 'react'
24+
25+
export default class App extends React.Component<{title: string}, void> {
26+
render() {
27+
return <div>{ this.props.title }</div>
28+
}
29+
}
30+
`);
31+
32+
tsconfig({
33+
jsx: 'react'
34+
});
35+
36+
await compile(webpackConfig(entry('index.tsx')));
37+
38+
expectErrors(0);
39+
});

src/__test__/remove.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {
2+
clear, src, webpackConfig, tsconfig,
3+
watch, expectErrors, xrun
4+
} from './utils';
5+
6+
xrun(__filename, async function() {
7+
clear();
8+
const index = src('index.ts', `
9+
import sum from './sum'
10+
import mul from './mul'
11+
12+
sum(1, 1)
13+
mul(1, 1)
14+
`);
15+
16+
src('sum.ts', `
17+
export default function sum(a: number, b: number) {
18+
return a + b;
19+
}
20+
`);
21+
22+
const mul = src('mul.ts', `
23+
// function with error
24+
export default function mul(a: number, b: number) {
25+
return a * c;
26+
}
27+
`);
28+
29+
tsconfig();
30+
const watcher = await watch(webpackConfig());
31+
32+
await watcher.wait();
33+
34+
expectErrors(1, [
35+
`Cannot find name 'c'`
36+
]);
37+
38+
index.update(() => `
39+
import sum from './sum'
40+
sum(1, 1)
41+
`);
42+
43+
mul.remove();
44+
45+
await watcher.wait();
46+
expectErrors(0);
47+
});

src/__test__/simple.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {
2+
clear, src, webpackConfig, tsconfig,
3+
compile, checkOutput, expectErrors, run
4+
} from './utils';
5+
6+
run(__filename, async function() {
7+
clear();
8+
src('index.ts', `
9+
class HiThere {
10+
constructor(a: number, b: string) {
11+
const t = a + b;
12+
}
13+
}
14+
`);
15+
16+
tsconfig();
17+
await compile(webpackConfig());
18+
19+
expectErrors(0);
20+
checkOutput('index.js', `
21+
class HiThere {
22+
constructor(a, b) {
23+
const t = a + b;
24+
}
25+
}
26+
`);
27+
});

0 commit comments

Comments
 (0)