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

Output lib array opt #562

Merged
merged 5 commits into from
Sep 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,49 @@ In case you are suggesting a new feature, we will match your idea with our curre
* `git clone <your-clone-url> && cd webpack-cli`

### Setup with npm
* Install the dependencies and bootstrap the packages: `npm install`
* Run the tests with: `npm test`

* Install the dependencies and link them:

```bash
npm install
npm link
npm link webpack-cli
```

* Run all the tests with:
- `npm run test`

* To test a single CLI (flag) test case:
- `BIN_TEST_CASES_GREP=/myCase jest test/BinTestCases.test.js`

* To test a single CLI (other type of) test case:
- `jest path/to/my-test.js`

* To test linting:
- `npm run lint && npm run tslint`

### Setup with yarn
* If you don't have yarn yet: `npm install -g yarn`
* If you don't have yarn yet:
- `npm install -g yarn`
* Install the dependencies and link them

```bash
yarn bootstrap
yarn
yarn link
yarn link webpack-cli
```

* To run the entire test suite use: `yarn test`
* Run all the tests with:
- `yarn test`

* To test a single CLI (flag) test case:
- `BIN_TEST_CASES_GREP=/myCase jest test/BinTestCases.test.js`

* To test a single CLI (other type of) test case:
- `jest path/to/my-test.js`

* To test linting:
- `yarn lint && yarn tslint`

## Editor Config

Expand Down
2 changes: 1 addition & 1 deletion bin/config-yargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ module.exports = function(yargs) {
group: OUTPUT_GROUP
},
"output-library": {
type: "string",
type: "array",
describe: "Expose the exports of the entry point as library",
group: OUTPUT_GROUP,
requiresArg: true
Expand Down
3 changes: 2 additions & 1 deletion bin/convert-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ module.exports = function(...args) {

ifArg("output-library", function(value) {
ensureObject(options, "output");
options.output.library = value;
ensureArray(options.output, "library");
options.output.library.push(value);
});

ifArg("output-library-target", function(value) {
Expand Down
2 changes: 2 additions & 0 deletions test/BinTestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ const defaultArgs = loadOptsFile(path.join(casesPath, "test.opts"));

describe("BinTestCases", function() {
const tests = findTestsRecursive(casesPath);
const patternFilter = process.env.BIN_TEST_CASES_GREP ? new RegExp(process.env.BIN_TEST_CASES_GREP) : null;

tests.forEach(testDirectory => {
const testName = testDirectory.replace(casesPath, "");
if (patternFilter && !testName.match(patternFilter)) return;
const testArgs = getTestSpecificArguments(testDirectory) || defaultArgs;
const testAssertions = require(path.join(testDirectory, "stdin.js"));
const outputPath = path.join(
Expand Down
1 change: 1 addition & 0 deletions test/binCases/output/output-library-many/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "index";
14 changes: 14 additions & 0 deletions test/binCases/output/output-library-many/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

const { readFileSync } = require("fs");
const { resolve } = require("path");

module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(0);
expect(stdout).toEqual(expect.anything());
expect(stdout[7]).toMatch(/index\.js.*\{0\}/);
expect(stderr).toHaveLength(0);
const outputPath = resolve("test", "js", "bin", "output", "output-library-many", "main.js");
const output = readFileSync(outputPath, "utf-8");
expect(output).toContain("window.key1=window.key1||{},window.key1.key2=function");
Copy link
Member

Choose a reason for hiding this comment

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

Maybe match this assertion using the array indice and regexes

Copy link
Member

Choose a reason for hiding this comment

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

expect(stdout[myIndices]).toMatch(/window.key1=window.key/*\{0\}/);

};
4 changes: 4 additions & 0 deletions test/binCases/output/output-library-many/test.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./index.js
--target async-node
--output-library-target window
--output-library key1 --output-library key2
1 change: 1 addition & 0 deletions test/binCases/output/output-library-single/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "index";
14 changes: 14 additions & 0 deletions test/binCases/output/output-library-single/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

const { readFileSync } = require("fs");
const { resolve } = require("path");

module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(0);
expect(stdout).toEqual(expect.anything());
expect(stdout[7]).toMatch(/index\.js.*\{0\}/);
expect(stderr).toHaveLength(0);
const outputPath = resolve("test", "js", "bin", "output", "output-library-single", "main.js");
const output = readFileSync(outputPath, "utf-8");
expect(output).toContain("window.key1=function");
Copy link
Member

Choose a reason for hiding this comment

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

see prev comment

};
4 changes: 4 additions & 0 deletions test/binCases/output/output-library-single/test.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./index.js
--target async-node
--output-library-target window
--output-library key1