Skip to content

Commit 42760f3

Browse files
snitin315alexander-akait
authored andcommitted
test: refactor
1 parent 83aff27 commit 42760f3

File tree

2 files changed

+60
-138
lines changed

2 files changed

+60
-138
lines changed

bin/cli-flags.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -359,46 +359,6 @@ module.exports = {
359359
simpleType: 'boolean',
360360
multiple: false,
361361
},
362-
firewall: {
363-
configs: [
364-
{
365-
type: 'boolean',
366-
multiple: false,
367-
description:
368-
'Defines routes which are enabled by default, on by default and allows localhost.',
369-
path: 'firewall',
370-
},
371-
{
372-
type: 'string',
373-
multiple: true,
374-
description:
375-
'Defines routes which are enabled by default, on by default and allows localhost.',
376-
path: 'firewall[]',
377-
},
378-
],
379-
description:
380-
'Defines routes which are enabled by default, on by default and allows localhost.',
381-
negatedDescription: 'Disable firewall.',
382-
simpleType: 'string',
383-
multiple: true,
384-
},
385-
'firewall-reset': {
386-
configs: [
387-
{
388-
type: 'reset',
389-
multiple: false,
390-
description: 'Clear all items provided in firewall configuration.',
391-
path: 'firewall',
392-
},
393-
],
394-
description: 'Clear all items provided in firewall configuration.',
395-
simpleType: 'boolean',
396-
multiple: false,
397-
processor(opts) {
398-
opts.firewall = opts.firewall || [];
399-
delete opts.firewallReset;
400-
},
401-
},
402362
'history-api-fallback': {
403363
configs: [
404364
{

test/cli/cli.test.js

Lines changed: 60 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const internalIp = require('internal-ip');
66
const stripAnsi = require('strip-ansi');
77
const { testBin, normalizeStderr } = require('../helpers/test-bin');
88

9+
const isMacOS = process.platform === 'darwin';
910
const localIPv4 = internalIp.v4.sync();
1011
const localIPv6 = internalIp.v6.sync();
1112

@@ -93,44 +94,45 @@ describe('CLI', () => {
9394
});
9495
});
9596

96-
describe('bonjour option', () => {});
97-
it('--bonjour', (done) => {
98-
testBin('--bonjour')
99-
.then((output) => {
100-
expect(output.exitCode).toEqual(0);
101-
expect(
102-
normalizeStderr(output.stderr, { ipv6: true })
103-
).toMatchSnapshot();
97+
describe('bonjour option', () => {
98+
it('--bonjour', (done) => {
99+
testBin('--bonjour')
100+
.then((output) => {
101+
expect(output.exitCode).toEqual(0);
102+
expect(
103+
normalizeStderr(output.stderr, { ipv6: true })
104+
).toMatchSnapshot();
104105

105-
done();
106-
})
107-
.catch(done);
108-
});
106+
done();
107+
})
108+
.catch(done);
109+
});
109110

110-
it('--bonjour and --https', (done) => {
111-
testBin('--bonjour --https')
112-
.then((output) => {
113-
expect(output.exitCode).toEqual(0);
114-
expect(
115-
normalizeStderr(output.stderr, { ipv6: true, https: true })
116-
).toMatchSnapshot();
111+
it('--bonjour and --https', (done) => {
112+
testBin('--bonjour --https')
113+
.then((output) => {
114+
expect(output.exitCode).toEqual(0);
115+
expect(
116+
normalizeStderr(output.stderr, { ipv6: true, https: true })
117+
).toMatchSnapshot();
117118

118-
done();
119-
})
120-
.catch(done);
121-
});
119+
done();
120+
})
121+
.catch(done);
122+
});
122123

123-
it('--no-bonjour', (done) => {
124-
testBin('--no-bonjour')
125-
.then((output) => {
126-
expect(output.exitCode).toEqual(0);
127-
expect(
128-
normalizeStderr(output.stderr, { ipv6: true })
129-
).toMatchSnapshot();
124+
it('--no-bonjour', (done) => {
125+
testBin('--no-bonjour')
126+
.then((output) => {
127+
expect(output.exitCode).toEqual(0);
128+
expect(
129+
normalizeStderr(output.stderr, { ipv6: true })
130+
).toMatchSnapshot();
130131

131-
done();
132-
})
133-
.catch(done);
132+
done();
133+
})
134+
.catch(done);
135+
});
134136
});
135137

136138
describe('client option', () => {
@@ -915,19 +917,11 @@ describe('CLI', () => {
915917
});
916918
});
917919

918-
it('should generate correct cli flags', (done) => {
919-
const isMacOS = process.platform === 'darwin';
920-
920+
(isMacOS ? it.skip : it)('should generate correct cli flags', (done) => {
921921
testBin('--help')
922922
.then((output) => {
923-
// TODO: find a fix, skip for MacOS
924-
if (isMacOS) {
925-
expect(output.exitCode).toBe(0);
926-
done();
927-
} else {
928-
expect(stripAnsi(output.stdout)).toMatchSnapshot();
929-
done();
930-
}
923+
expect(stripAnsi(output.stdout)).toMatchSnapshot();
924+
done();
931925
})
932926
.catch(done);
933927
});
@@ -937,76 +931,57 @@ describe('CLI', () => {
937931
testBin('--static')
938932
.then((output) => {
939933
expect(output.exitCode).toEqual(0);
934+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
940935
done();
941936
})
942937
.catch(done);
943938
});
944939

945940
it('--static <value>', (done) => {
946-
testBin(
947-
`--static ${path.resolve(
948-
__dirname,
949-
'../fixtures/static/webpack.config.js'
950-
)}`
951-
)
941+
testBin('--static new-static')
952942
.then((output) => {
953943
expect(output.exitCode).toEqual(0);
944+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
954945
done();
955946
})
956947
.catch(done);
957948
});
958949

959950
it('--static-reset', (done) => {
960-
testBin(
961-
`--static-reset --static ${path.resolve(
962-
__dirname,
963-
'../fixtures/static/webpack.config.js'
964-
)}`
965-
)
951+
testBin('--static-reset --static new-static-after-reset')
966952
.then((output) => {
967953
expect(output.exitCode).toEqual(0);
954+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
968955
done();
969956
})
970957
.catch(done);
971958
});
972959

973960
it('--static-reset --static-directory <value>', (done) => {
974-
testBin(
975-
`--static-reset --static-directory ${path.resolve(
976-
__dirname,
977-
'../fixtures/static/webpack.config.js'
978-
)}`
979-
)
961+
testBin('--static-reset --static-directory new-static-directory')
980962
.then((output) => {
981963
expect(output.exitCode).toEqual(0);
964+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
982965
done();
983966
})
984967
.catch(done);
985968
});
986969

987970
it('--static-directory', (done) => {
988-
testBin(
989-
`--static-directory ${path.resolve(
990-
__dirname,
991-
'../fixtures/static/webpack.config.js'
992-
)}`
993-
)
971+
testBin('--static-directory static-dir')
994972
.then((output) => {
995973
expect(output.exitCode).toEqual(0);
974+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
996975
done();
997976
})
998977
.catch(done);
999978
});
1000979

1001980
it('--static --static-directory', (done) => {
1002-
testBin(
1003-
`--static --static-directory ${path.resolve(
1004-
__dirname,
1005-
'../fixtures/static/webpack.config.js'
1006-
)}`
1007-
)
981+
testBin('--static --static-directory static-dir')
1008982
.then((output) => {
1009983
expect(output.exitCode).toEqual(0);
984+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
1010985
done();
1011986
})
1012987
.catch(done);
@@ -1016,6 +991,7 @@ describe('CLI', () => {
1016991
testBin('--static-public-path /public')
1017992
.then((output) => {
1018993
expect(output.exitCode).toEqual(0);
994+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
1019995
done();
1020996
})
1021997
.catch(done);
@@ -1025,6 +1001,7 @@ describe('CLI', () => {
10251001
testBin('--static-public-path-reset --static-public-path /new-public')
10261002
.then((output) => {
10271003
expect(output.exitCode).toEqual(0);
1004+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
10281005
done();
10291006
})
10301007
.catch(done);
@@ -1034,6 +1011,7 @@ describe('CLI', () => {
10341011
testBin('--static-serve-index')
10351012
.then((output) => {
10361013
expect(output.exitCode).toEqual(0);
1014+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
10371015
done();
10381016
})
10391017
.catch(done);
@@ -1043,6 +1021,7 @@ describe('CLI', () => {
10431021
testBin('--no-static-serve-index')
10441022
.then((output) => {
10451023
expect(output.exitCode).toEqual(0);
1024+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
10461025
done();
10471026
})
10481027
.catch(done);
@@ -1052,6 +1031,7 @@ describe('CLI', () => {
10521031
testBin('--static-watch')
10531032
.then((output) => {
10541033
expect(output.exitCode).toEqual(0);
1034+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
10551035
done();
10561036
})
10571037
.catch(done);
@@ -1061,34 +1041,11 @@ describe('CLI', () => {
10611041
testBin('--static-watch')
10621042
.then((output) => {
10631043
expect(output.exitCode).toEqual(0);
1044+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
10641045
done();
10651046
})
10661047
.catch(done);
10671048
});
1068-
1069-
it('should log static', (done) => {
1070-
testBin(
1071-
'--no-color',
1072-
path.resolve(__dirname, '../fixtures/static/webpack.config.js')
1073-
)
1074-
.then((output) => {
1075-
expect(output.exitCode).toEqual(0);
1076-
done();
1077-
})
1078-
.catch((err) => {
1079-
const staticDirectory = path.resolve(
1080-
__dirname,
1081-
'../fixtures/static/static'
1082-
);
1083-
1084-
// for windows
1085-
expect(err.stderr).toContain(
1086-
`Content not from webpack is served from '${staticDirectory}' directory`
1087-
);
1088-
expect(err.stdout).toContain('main.js');
1089-
done();
1090-
});
1091-
});
10921049
});
10931050

10941051
describe('watchFiles option', () => {
@@ -1101,6 +1058,7 @@ describe('CLI', () => {
11011058
testBin(`--watch-files ${watchDirectory}`)
11021059
.then((output) => {
11031060
expect(output.exitCode).toEqual(0);
1061+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
11041062
done();
11051063
})
11061064
.catch(done);
@@ -1115,6 +1073,7 @@ describe('CLI', () => {
11151073
testBin(`--watch-files-reset --watch-files ${watchDirectory}`)
11161074
.then((output) => {
11171075
expect(output.exitCode).toEqual(0);
1076+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
11181077
done();
11191078
})
11201079
.catch(done);
@@ -1129,6 +1088,7 @@ describe('CLI', () => {
11291088
testBin(`--watch-files-reset --watch-files-paths ${watchDirectory}`)
11301089
.then((output) => {
11311090
expect(output.exitCode).toEqual(0);
1091+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
11321092
done();
11331093
})
11341094
.catch(done);
@@ -1143,6 +1103,7 @@ describe('CLI', () => {
11431103
testBin(`--watch-files-paths ${watchDirectory}`)
11441104
.then((output) => {
11451105
expect(output.exitCode).toEqual(0);
1106+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
11461107
done();
11471108
})
11481109
.catch(done);
@@ -1157,6 +1118,7 @@ describe('CLI', () => {
11571118
testBin(`--watch-files-paths-reset --watch-files-paths ${watchDirectory}`)
11581119
.then((output) => {
11591120
expect(output.exitCode).toEqual(0);
1121+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
11601122
done();
11611123
})
11621124
.catch(done);

0 commit comments

Comments
 (0)