Skip to content

Commit

Permalink
tests(migration): typescript (#613)
Browse files Browse the repository at this point in the history
* chore(test): add migrate test

* chore(lint): revert change

* chore(test): moved to typescript migrate tests

* tests(ts): moved module concatenation plugin to ts

* tests(migrate): moved to typescript

* tests(webpack-scaffold): moved to typescript

* tests(migrate): clean js text fixtures

* tests(migrate): update babel-loader test

* tests(migrate): update babel-loader snapshot

* tests(utils): move tests to TS (#688)

* chore(test): add migrate test

* chore(lint): revert change

* chore(test): moved to typescript migrate tests

* tests(ts): moved module concatenation plugin to ts

* tests(migrate): moved to typescript

* tests(webpack-scaffold): moved to typescript

* tests(utils): copy fixtures to __tests_

* tests(utils): move package-manager.test.js to TS

* tests(utils): move validate-identifier.test.js to TS

* tests(utils): move resolve-packages.test.js to TS

* tests(utils): is-local-path.test.js to TS

* tests(utils): move npm-exists.test.js to TS

* tests(utils): move ast-utils.test.js to TS

* tests(utils): WIP-test-cases

* tests(utils): move recursive-parser.test.js to TS

* tests(utils): move npm-package-exists.test.js to TS

* tests(utils): cleanup .js , __fixtures__ and __snapshots__ files

* chore(utils): clean console recursive-parser.test.ts

* chore(utils): make options param optional

* chore: use INode in ast-utils.test.ts

* tests(migrate): adds interface ILazyTransformObject

* chore(commitlint): remove deprecated lang rule

* chore(typings): fix tslint error

* tests(migration): refactor dirName in a variable

* tests(migrate): refactor dirName in variable 2

* tests(migrate): import path.resolve & add rootPath variable

* tests(utils): adds type in forEach

* tests(migrate): refactor resolve.test

* chore(tests): enable ts in tests

* chore(tests): remove unwanted script
  • Loading branch information
dhruvdutt authored and ematipico committed Mar 16, 2019
1 parent 2af08be commit 2106e70
Show file tree
Hide file tree
Showing 168 changed files with 1,502 additions and 1,335 deletions.
11 changes: 8 additions & 3 deletions package.json
Expand Up @@ -63,7 +63,6 @@
},
"jest": {
"testPathIgnorePatterns": [
"^.+\\.(ts)?$",
"/node_modules/"
],
"testEnvironment": "node",
Expand All @@ -73,9 +72,15 @@
"html",
"cobertura"
],
"moduleNameMapper": {
"transform": {
"^.+\\.(ts)?$": "ts-jest"
}
},
"testRegex": "/__tests__/.*\\.(test.js|test.ts)$",
"moduleFileExtensions": [
"ts",
"js",
"json"
]
},
"nyc": {
"include": [
Expand Down
10 changes: 9 additions & 1 deletion packages/add/README.md
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").default;
add();
```

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

```bash
npx webpack-cli add
```
```
15 changes: 7 additions & 8 deletions packages/add/index.ts
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
@@ -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();
});
});
});
8 changes: 8 additions & 0 deletions packages/migrate/bannerPlugin/__tests__/bannerPlugin.test.ts
@@ -0,0 +1,8 @@
import defineTest from "@webpack-cli/utils/defineTest";
import { join } from "path";

const dirName: string = join(__dirname, "..");

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

This file was deleted.

@@ -0,0 +1,32 @@
import defineTest from "@webpack-cli/utils/defineTest";
import { join } from "path";

const dirName: string = join(__dirname, "..");

defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-0");
defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-1");
defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-2");
defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-3");
defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-4");
defineTest(dirName, "commonsChunkPlugin", "commonsChunkPlugin-5");
defineTest(
dirName,
"commonsChunkPlugin",
"commonsChunkPlugin-6a",
);
defineTest(
dirName,
"commonsChunkPlugin",
"commonsChunkPlugin-6b",
);
defineTest(
dirName,
"commonsChunkPlugin",
"commonsChunkPlugin-6c",
);
defineTest(
dirName,
"commonsChunkPlugin",
"commonsChunkPlugin-6d",
);
defineTest(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.

@@ -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\\")]
};
"
`;
@@ -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")]
};
@@ -0,0 +1,5 @@
import defineTest from "@webpack-cli/utils/defineTest";
import { join } from "path";

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

This file was deleted.

2 changes: 1 addition & 1 deletion packages/migrate/index.ts
Expand Up @@ -18,7 +18,7 @@ declare var process: {
validate: Function;
/* tslint:disable */
WebpackOptionsValidationError: {
new(errors: string[]): {
new: (errors: string[]) => {
message: string;
};
};
Expand Down
@@ -0,0 +1,25 @@
import defineTest from "@webpack-cli/utils/defineTest";
import { join } from "path";

const dirName: string = join(__dirname, "..");

defineTest(
dirName,
"loaderOptionsPlugin",
"loaderOptionsPlugin-0",
);
defineTest(
dirName,
"loaderOptionsPlugin",
"loaderOptionsPlugin-1",
);
defineTest(
dirName,
"loaderOptionsPlugin",
"loaderOptionsPlugin-2",
);
defineTest(
dirName,
"loaderOptionsPlugin",
"loaderOptionsPlugin-3",
);

This file was deleted.

0 comments on commit 2106e70

Please sign in to comment.