Skip to content

Commit 11ca41c

Browse files
authored
tests: rm duplicate code for hypenToUpperCase util (#1888)
1 parent 8df291e commit 11ca41c

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const { commands } = require('./cli-flags');
22

3-
function hyphenToUpperCase(name) {
3+
const hyphenToUpperCase = (name) => {
44
if (!name) {
55
return name;
66
}
77
return name.replace(/-([a-z])/g, function (g) {
88
return g[1].toUpperCase();
99
});
10-
}
10+
};
1111

12-
function arrayToObject(arr) {
12+
const arrayToObject = (arr) => {
1313
if (!arr) {
1414
return;
1515
}
@@ -18,7 +18,7 @@ function arrayToObject(arr) {
1818
result[hyphenToUpperCase(key)] = currentItem[key];
1919
return result;
2020
}, {});
21-
}
21+
};
2222

2323
const isCommandUsed = (args) =>
2424
commands.find((cmd) => {
@@ -27,5 +27,6 @@ const isCommandUsed = (args) =>
2727

2828
module.exports = {
2929
arrayToObject,
30+
hyphenToUpperCase,
3031
isCommandUsed,
3132
};

test/utils/test-utils.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { sync: spawnSync, node: execaNode } = execa;
66
const { Writable } = require('readable-stream');
77
const concat = require('concat-stream');
88
const { version } = require('webpack');
9+
const { hyphenToUpperCase } = require('../../packages/webpack-cli/lib/utils/arg-utils');
910

1011
const WEBPACK_PATH = path.resolve(__dirname, '../../packages/webpack-cli/bin/cli.js');
1112
const ENABLE_LOG_COMPILATION = process.env.ENABLE_PIPE || false;
@@ -235,15 +236,6 @@ const runInfo = (args, testPath) => {
235236
return run(testPath, ['info'].concat(args), false);
236237
};
237238

238-
const hyphenToUpperCase = (name) => {
239-
if (!name) {
240-
return name;
241-
}
242-
return name.replace(/-([a-z])/g, function (g) {
243-
return g[1].toUpperCase();
244-
});
245-
};
246-
247239
const isWindows = process.platform === 'win32';
248240

249241
module.exports = {

test/utils/test-utils.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { appendDataIfFileExists, run, runAndGetWatchProc } = require('./test-utils');
3+
const { appendDataIfFileExists, run, runAndGetWatchProc, hyphenToUpperCase } = require('./test-utils');
44
const { writeFileSync, unlinkSync, readFileSync } = require('fs');
55
const { resolve } = require('path');
66

@@ -106,3 +106,10 @@ describe('runAndGetWatchProc function', () => {
106106
expect(stdout).toContain('Which will be your application entry point?');
107107
});
108108
});
109+
110+
describe('hyphenToUpperCase function', () => {
111+
it('changes value from hypen to upperCase', () => {
112+
const result = hyphenToUpperCase('test-value');
113+
expect(result).toEqual('testValue');
114+
});
115+
});

0 commit comments

Comments
 (0)