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

Commit

Permalink
feat: refactor tests, fix #349, #323, #335
Browse files Browse the repository at this point in the history
  • Loading branch information
s-panferov committed Jan 29, 2017
1 parent 6bd83ff commit 1436114
Show file tree
Hide file tree
Showing 67 changed files with 939 additions and 5,075 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ src/test/output
.vagrant
Vagrantfile
issues
.idea
.idea
.test
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
sudo: false
language: node_js
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH
before_script:
- npm i
- npm run compile
- yarn i
- yarn run build
node_js:
- "7"
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var loader = require('./dist');

module.exports = loader;
36 changes: 17 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"typings": "./dist/index.d.ts",
"scripts": {
"prepublish": "npm run build",
"test": "mocha dist/test --harmony-async-await",
"watch": "npm run watch:ts",
"watch:ts": "npm run build:ts -- --watch --diagnostics",
"prebuild": "npm run lint",
"compile": "tsc --pretty",
"build": "rm -rf dist && tsc -p prod --pretty",
"build": "rm -rf dist && tsc --pretty",
"lint": "tslint src/*.ts",
"release": "standard-version"
"release": "standard-version",
"test": "mocha --timeout 10000 dist/__test__"
},
"author": "Stanislav Panferov <[email protected]> (http://panferov.me/)",
"repository": {
Expand All @@ -33,34 +33,32 @@
"homepage": "https://github.com/s-panferov/awesome-typescript-loader",
"dependencies": {
"colors": "^1.1.2",
"enhanced-resolve": "^2.3.0",
"enhanced-resolve": "^3.0.3",
"loader-utils": "^0.2.16",
"lodash": "^4.13.1",
"object-assign": "^4.1.0",
"source-map-support": "^0.4.0"
"lodash": "^4.17.4",
"object-assign": "^4.1.1",
"source-map-support": "^0.4.11"
},
"devDependencies": {
"@types/chai": "^3.4.34",
"@types/colors": "^0.6.33",
"@types/lodash": "^4.14.43",
"@types/mocha": "^2.2.32",
"@types/node": "^6.0.46",
"@types/sinon": "^1.16.31",
"babel-core": "^6.20.0",
"babel-preset-es2015": "^6.18.0",
"bluebird": "^3.4.1",
"@types/colors": "^1.1.1",
"@types/lodash": "^4.14.51",
"@types/mocha": "^2.2.38",
"@types/node": "^7.0.4",
"@types/sinon": "^1.16.34",
"bluebird": "^3.4.7",
"chai": "^3.5.0",
"empty-module": "0.0.2",
"fs-extra": "^2.0.0",
"git-hooks": "^1.0.2",
"mkdirp": "^0.5.1",
"mocha": "^3.2.0",
"ps-node": "^0.1.1",
"rimraf": "^2.5.0",
"sinon": "^1.17.4",
"standard-version": "^4.0.0",
"temp": "^0.8.3",
"tslint": "^4.0.2",
"typescript": "^2.1.4",
"webpack": "2.1.0-beta.25"
"tslint": "^4.4.2",
"typescript": "^2.1.5",
"webpack": "2.2.0"
}
}
58 changes: 58 additions & 0 deletions src/__test__/babel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
clear, src, webpackConfig, tsconfig, install,
watch, checkOutput, expectErrors, query, run
} from './utils';

run(__filename, async function() {
clear();
const index = src('index.ts', `
class HiThere {
constructor(a: number, b: string) {
const t = a + b;
}
}
`);

install('babel-core', 'babel-preset-es2015');
tsconfig();

const watcher = await watch(webpackConfig(query({
useBabel: true,
babelOptions: {
"presets": ["es2015"]
}
})));

await watcher.wait();

expectErrors(0);
checkOutput('index.js', `
var HiThere = function HiThere(a, b) {
_classCallCheck(this, HiThere);
var t = a + b;
}
`);

index.update(() => `
function sum(...items: number[]) {
return items.reduce((a,b) => a + b, 0);
}
`);

await watcher.wait();

expectErrors(0);
checkOutput('index.js', `
function sum() {
for(var _len = arguments.length,
items = Array(_len),
_key = 0;
_key < _len;
_key++
) {
items[_key] = arguments[_key];
}
return items.reduce(function(a,b){ return a + b; }, 0);
}
`);
});
57 changes: 57 additions & 0 deletions src/__test__/declaration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
clear, src, webpackConfig, tsconfig,
watch, checkOutput, expectErrors, run
} from './utils';

run(__filename, async function() {
clear();
const index = src('index.ts', `
export { default as sum } from './utils/sum'
`);

src('utils/sum.ts', `
export default function sum(a: number, b: number) {
return a + b;
}
`);

tsconfig({
declaration: true
});

const watcher = watch(webpackConfig());

await watcher.wait();

expectErrors(0);

checkOutput('src/index.d.ts', `
export { default as sum } from './utils/sum'
`);

checkOutput('src/utils/sum.d.ts', `
export default function sum(a: number, b: number): number
`);

src('utils/mul.ts', `
export default function mul(a: number, b: number) {
return a * b;
}
`);

index.update(() => `
export { default as sum } from './utils/sum'
export { default as mul } from './utils/mul'
`);

await watcher.wait();

checkOutput('src/utils/mul.d.ts', `
export default function mul(a: number, b: number): number
`);

checkOutput('src/index.d.ts', `
export { default as sum } from './utils/sum';
export { default as mul } from './utils/mul';
`);
});
31 changes: 31 additions & 0 deletions src/__test__/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
clear, src, webpackConfig, tsconfig,
compile, checkOutput, expectErrors, run
} from './utils';

run(__filename, async function() {
clear();
src('index.ts', `
function sum(a: number, b: number) {
return a + b;
}
sum('test', 1);
`);

tsconfig();

await compile(webpackConfig());

expectErrors(1, [
`Argument of type '"test"' is not assignable to parameter of type 'number'`
]);

checkOutput('index.js', `
function sum(a, b) {
return a + b;
}
sum('test', 1);
`);
});
39 changes: 39 additions & 0 deletions src/__test__/react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
clear, src, webpackConfig, expectErrors,
tsconfig, compile, install, entry, run
} from './utils';

run(__filename, async function() {
clear();
install(
'react',
'react-dom',
'@types/react',
'@types/react-dom'
);

src('index.tsx', `
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import App from './app'
ReactDOM.render(<App title='Test' />, document.body)
`);

src('app.tsx', `
import * as React from 'react'
export default class App extends React.Component<{title: string}, void> {
render() {
return <div>{ this.props.title }</div>
}
}
`);

tsconfig({
jsx: 'react'
});

await compile(webpackConfig(entry('index.tsx')));

expectErrors(0);
});
47 changes: 47 additions & 0 deletions src/__test__/remove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
clear, src, webpackConfig, tsconfig,
watch, expectErrors, xrun
} from './utils';

xrun(__filename, async function() {
clear();
const index = src('index.ts', `
import sum from './sum'
import mul from './mul'
sum(1, 1)
mul(1, 1)
`);

src('sum.ts', `
export default function sum(a: number, b: number) {
return a + b;
}
`);

const mul = src('mul.ts', `
// function with error
export default function mul(a: number, b: number) {
return a * c;
}
`);

tsconfig();
const watcher = await watch(webpackConfig());

await watcher.wait();

expectErrors(1, [
`Cannot find name 'c'`
]);

index.update(() => `
import sum from './sum'
sum(1, 1)
`);

mul.remove();

await watcher.wait();
expectErrors(0);
});
27 changes: 27 additions & 0 deletions src/__test__/simple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
clear, src, webpackConfig, tsconfig,
compile, checkOutput, expectErrors, run
} from './utils';

run(__filename, async function() {
clear();
src('index.ts', `
class HiThere {
constructor(a: number, b: string) {
const t = a + b;
}
}
`);

tsconfig();
await compile(webpackConfig());

expectErrors(0);
checkOutput('index.js', `
class HiThere {
constructor(a, b) {
const t = a + b;
}
}
`);
});
Loading

0 comments on commit 1436114

Please sign in to comment.