Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(utils): move tests to TS #688

Merged
merged 21 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0a590a0
chore(test): add migrate test
sendilkumarn Sep 25, 2018
dc79068
chore(lint): revert change
sendilkumarn Sep 25, 2018
dd3a76c
chore(test): moved to typescript migrate tests
ematipico Sep 29, 2018
aa80327
tests(ts): moved module concatenation plugin to ts
ematipico Sep 29, 2018
5a34a88
tests(migrate): moved to typescript
ematipico Oct 1, 2018
122a770
tests(webpack-scaffold): moved to typescript
hemal7735 Nov 6, 2018
3a9656a
tests(utils): copy fixtures to __tests_
hemal7735 Nov 7, 2018
a3c9e32
tests(utils): move package-manager.test.js to TS
hemal7735 Nov 7, 2018
bb7e3ed
tests(utils): move validate-identifier.test.js to TS
hemal7735 Nov 7, 2018
655715d
tests(utils): move resolve-packages.test.js to TS
hemal7735 Nov 7, 2018
f470f5f
tests(utils): is-local-path.test.js to TS
hemal7735 Nov 7, 2018
182f0bb
tests(utils): move npm-exists.test.js to TS
hemal7735 Nov 7, 2018
86b5d7d
tests(utils): move ast-utils.test.js to TS
hemal7735 Nov 7, 2018
c2c1479
tests(utils): WIP-test-cases
hemal7735 Nov 8, 2018
b351fa2
tests(utils): move recursive-parser.test.js to TS
hemal7735 Nov 12, 2018
7bda1ff
tests(utils): move npm-package-exists.test.js to TS
hemal7735 Nov 12, 2018
1c8d42a
tests(utils): cleanup .js , __fixtures__ and __snapshots__ files
hemal7735 Nov 12, 2018
cbb9bae
chore(utils): clean console recursive-parser.test.ts
hemal7735 Nov 16, 2018
46365a2
chore(utils): make options param optional
hemal7735 Nov 16, 2018
aec65b8
Merge remote-tracking branch 'GRO/ts-test' into ts-test-utils
hemal7735 Nov 16, 2018
8af2a8b
chore: use INode in ast-utils.test.ts
hemal7735 Nov 17, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"travis:integration": "npm run build && npm run test && npm run reportCoverage",
"travis:lint": "lerna bootstrap && npm run build && npm run lint && npm run tslint && npm run bundlesize",
"tslint": "tslint -c tslint.json \"packages/**/*.ts\"",
"watch": "npm run build && tsc -w"
"watch": "npm run build && tsc -w",
"test:local": "jest --watch"
},
"husky": {
"hooks": {
Expand All @@ -68,9 +69,14 @@
"json",
"html"
],
"moduleNameMapper": {
"transform": {
"^.+\\.(ts)?$": "ts-jest"
}
},
"testRegex": "/__tests__/.*\\.(test.js|test.ts)$",
"moduleFileExtensions": [
"ts",
"js"
]
},
"nyc": {
"include": [
Expand Down
10 changes: 9 additions & 1 deletion packages/add/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@ This package contains the logic to add new properties in a webpack configuration
npm i -D webpack-cli @webpack-cli/add
```

or

```bash
yarn add --dev webpack-cli @webpack-cli/add
```

## Usage

To run the scaffolding instance programmatically, install it as a dependency. When using the package programmatically, one does not have to install webpack-cli.

### Node

```js
const add = require("@webpack-cli/add");
add();
```

### CLI (via `webpack-cli`)

```bash
npx webpack-cli add
```
```
15 changes: 7 additions & 8 deletions packages/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import modifyConfigHelper from "@webpack-cli/utils/modify-config-helper";
* we're given on a generator
*
*/
const DEFAULT_WEBPACK_CONFIG_FILENAME: string = "webpack.config.js";

export default function add(...args: string[]): Function {
const DEFAULT_WEBPACK_CONFIG_FILENAME: string = "webpack.config.js";
const filePaths: string[] = args.slice(3);
let configFile: string = DEFAULT_WEBPACK_CONFIG_FILENAME;
if (filePaths.length) {
configFile = filePaths[0];
}

const filePaths: string[] = args.slice(3);
let configFile: string = DEFAULT_WEBPACK_CONFIG_FILENAME;
if (filePaths.length) {
configFile = filePaths[0];
}

return modifyConfigHelper("add", defaultGenerator, configFile);
return modifyConfigHelper("add", defaultGenerator, configFile);
}
63 changes: 63 additions & 0 deletions packages/migrate/__tests__/migrate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { transform, transformations } from "../migrate";

const input = `
module.exports = {
devtool: 'eval',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
loaders: [{
test: /.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
}]
},
resolve: {
root: path.resolve('/src'),
modules: ['node_modules']
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
],
debug: true
};
`;

describe("transform", () => {
it("should not transform if no transformations defined", (done) => {
transform(input, []).then((output) => {
expect(output).toMatchSnapshot(input);
done();
});
});

it("should transform using all transformations", (done) => {
transform(input).then((output) => {
expect(output).toMatchSnapshot();
done();
});
});

it("should transform only using specified transformations", (done) => {
transform(input, [transformations.loadersTransform]).then((output) => {
expect(output).toMatchSnapshot();
done();
});
});

it("should respect recast options", (done) => {
transform(input, undefined, {
quote: "double",
trailingComma: true,
}).then((output) => {
expect(output).toMatchSnapshot();
done();
});
});
});
6 changes: 6 additions & 0 deletions packages/migrate/bannerPlugin/__tests__/bannerPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import defineTest from "@webpack-cli/utils/defineTest";
import { join } from "path";

defineTest(join(__dirname, ".."), "bannerPlugin", "bannerPlugin-0");
defineTest(join(__dirname, ".."), "bannerPlugin", "bannerPlugin-1");
defineTest(join(__dirname, ".."), "bannerPlugin", "bannerPlugin-2");
7 changes: 0 additions & 7 deletions packages/migrate/bannerPlugin/bannerPlugin.test.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import defineTest from "@webpack-cli/utils/defineTest";
import { join } from "path";

defineTest(join(__dirname, ".."), "commonsChunkPlugin", "commonsChunkPlugin-0");
defineTest(join(__dirname, ".."), "commonsChunkPlugin", "commonsChunkPlugin-1");
defineTest(join(__dirname, ".."), "commonsChunkPlugin", "commonsChunkPlugin-2");
defineTest(join(__dirname, ".."), "commonsChunkPlugin", "commonsChunkPlugin-3");
defineTest(join(__dirname, ".."), "commonsChunkPlugin", "commonsChunkPlugin-4");
defineTest(join(__dirname, ".."), "commonsChunkPlugin", "commonsChunkPlugin-5");
defineTest(
join(__dirname, ".."),
"commonsChunkPlugin",
"commonsChunkPlugin-6a",
);
defineTest(
join(__dirname, ".."),
"commonsChunkPlugin",
"commonsChunkPlugin-6b",
);
defineTest(
join(__dirname, ".."),
"commonsChunkPlugin",
"commonsChunkPlugin-6c",
);
defineTest(
join(__dirname, ".."),
"commonsChunkPlugin",
"commonsChunkPlugin-6d",
);
defineTest(join(__dirname, ".."), "commonsChunkPlugin", "commonsChunkPlugin-7");
15 changes: 0 additions & 15 deletions packages/migrate/commonsChunkPlugin/commonsChunkPlugin.test.js

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`extractTextPlugin transforms correctly 1`] = `
"const ExtractTextPlugin = require(\\"extract-text-webpack-plugin\\");

module.exports = {
module: {
rules: [
{
test: /\\\\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
}
]
},
plugins: [new ExtractTextPlugin(\\"styles.css\\")]
};
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract("style-loader", "css-loader")
}
]
},
plugins: [new ExtractTextPlugin("styles.css")]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import defineTest from "@webpack-cli/utils/defineTest";
import { join } from "path";

defineTest(join(__dirname, ".."), "extractTextPlugin");
5 changes: 0 additions & 5 deletions packages/migrate/extractTextPlugin/extractTextPlugin.test.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import defineTest from "@webpack-cli/utils/defineTest";
import { join } from "path";
defineTest(
join(__dirname, ".."),
"loaderOptionsPlugin",
"loaderOptionsPlugin-0",
);
defineTest(
join(__dirname, ".."),
"loaderOptionsPlugin",
"loaderOptionsPlugin-1",
);
defineTest(
join(__dirname, ".."),
"loaderOptionsPlugin",
"loaderOptionsPlugin-2",
);
defineTest(
join(__dirname, ".."),
"loaderOptionsPlugin",
"loaderOptionsPlugin-3",
);

This file was deleted.