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 1 commit
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
2 changes: 1 addition & 1 deletion bin/config-yargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,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 fs = require("fs");
Copy link
Member

Choose a reason for hiding this comment

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

const {readFileSync} = require('fs')
const {join} = require('path')


const output = readFileSync(join(__dirname, __dirname, "..", "..", ".., "js", "bin", "output", output-library-many", "main.js"), "utf-8")

const path = 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 output = fs.readFileSync(path.join(__dirname, "../../../js/bin/output/output-library-many/main.js"), "utf-8");
Copy link
Member

Choose a reason for hiding this comment

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

could you abstract this a lil better? Quite long line and slashes that could be trimmed down using path.resolve

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 fs = require("fs");
const path = 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 output = fs.readFileSync(path.join(__dirname, "../../../js/bin/output/output-library-single/main.js"), "utf-8");
Copy link
Member

Choose a reason for hiding this comment

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

this should probably be in an own variable

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 👍

Copy link
Member

Choose a reason for hiding this comment

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

se prev comment

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