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(migration): typescript #613

Merged
merged 22 commits into from Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ef09f3b
chore(test): add migrate test
sendilkumarn Sep 25, 2018
fcab1fe
chore(lint): revert change
sendilkumarn Sep 25, 2018
2a86442
chore(test): moved to typescript migrate tests
ematipico Sep 29, 2018
46355b8
tests(ts): moved module concatenation plugin to ts
ematipico Sep 29, 2018
2c73046
tests(migrate): moved to typescript
ematipico Oct 1, 2018
aaa28a3
tests(webpack-scaffold): moved to typescript
hemal7735 Nov 6, 2018
1a80233
tests(migrate): clean js text fixtures
dhruvdutt Nov 16, 2018
7e60efe
tests(migrate): update babel-loader test
dhruvdutt Nov 16, 2018
b4f114b
tests(migrate): update babel-loader snapshot
dhruvdutt Nov 16, 2018
dd238a8
tests(utils): move tests to TS (#688)
hemal7735 Nov 17, 2018
d6d27dc
tests(migrate): adds interface ILazyTransformObject
misterdev Feb 19, 2019
eb7a457
chore(commitlint): remove deprecated lang rule
misterdev Feb 19, 2019
34aa982
chore(typings): fix tslint error
misterdev Feb 19, 2019
a98e867
tests(migration): refactor dirName in a variable
misterdev Feb 19, 2019
31220a3
tests(migrate): refactor dirName in variable 2
misterdev Feb 19, 2019
44da46b
tests(migrate): import path.resolve & add rootPath variable
misterdev Feb 19, 2019
ef8987d
tests(utils): adds type in forEach
misterdev Feb 19, 2019
a2e187f
tests(migrate): refactor resolve.test
misterdev Feb 19, 2019
210ef72
Merge pull request #765 from misterdev/misterdev-ts-test-fixreview
evenstensberg Mar 3, 2019
83a93e0
Merge branch 'master' into ts-test
sendilkumarn Mar 15, 2019
55ecafa
chore(tests): enable ts in tests
sendilkumarn Mar 15, 2019
67788ee
chore(tests): remove unwanted script
sendilkumarn Mar 15, 2019
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
1 change: 0 additions & 1 deletion commitlint.config.js
Expand Up @@ -12,7 +12,6 @@ module.exports = {
"body-leading-blank": [1, "always"],
"footer-leading-blank": [1, "always"],
"header-max-length": [2, "always", 80],
lang: [0, "always", "eng"],
"scope-case": [2, "always", "lowerCase"],
"scope-empty": [0, "never"],
"subject-case": [2, "never", ["sentence-case", "start-case", "pascal-case", "upper-case"]],
Expand Down
13 changes: 10 additions & 3 deletions package.json
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we remove this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense 👍

},
"husky": {
"hooks": {
Expand All @@ -69,9 +70,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();
});
});
});
@@ -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");

This file was deleted.

2 changes: 1 addition & 1 deletion packages/migrate/index.ts
Expand Up @@ -17,7 +17,7 @@ declare var process: {
webpackModule: {
validate: Function;
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.