Skip to content

Commit

Permalink
tests: add tests for experiments related flags
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jun 20, 2020
1 parent 116479d commit f12efe4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/webpack-cli/lib/utils/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,5 @@ module.exports = {
group: BASIC_GROUP
} */
],
flagsFromCore: [...flagsFromCore],
};
20 changes: 20 additions & 0 deletions test/core-flags/experiments-flag.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const { run, hyphenToUpperCase } = require('../utils/test-utils');
const { flagsFromCore } = require('../../packages/webpack-cli/lib/utils/cli-flags');

const experimentsFlags = flagsFromCore.filter((flag) => flag.name.includes('experiments-'));

describe('experiments option related flag', () => {
experimentsFlags.forEach((flag) => {
// extract property name from flag name
const property = flag.name.split('experiments-')[1];
const propName = hyphenToUpperCase(property);

it(`should config ${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--${flag.name}`]);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: true`);
});
});
});
10 changes: 10 additions & 0 deletions test/utils/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ const runServe = (args, testPath) => {
});
};

const hyphenToUpperCase = (name) => {
if (!name) {
return name;
}
return name.replace(/-([a-z])/g, function (g) {
return g[1].toUpperCase();
});
};

module.exports = {
run,
runWatch,
Expand All @@ -304,4 +313,5 @@ module.exports = {
copyFileAsync,
appendDataToMultipleIfFilesExists,
runInstall,
hyphenToUpperCase,
};

0 comments on commit f12efe4

Please sign in to comment.