-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.js
98 lines (72 loc) · 2.73 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import process from 'node:process';
import test from 'ava';
import esmock from 'esmock';
const requireFresh = modulePath => import(`${modulePath}?cacheBust=${Date.now()}`);
test('inside WSL 1', async t => {
process.env.__IS_WSL_TEST__ = true;
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', {value: 'linux'});
const isWsl = await esmock('./index.js', {
fs: {
readFileSync: () => 'Linux version 3.4.0-Microsoft ([email protected]) (gcc version 4.7 (GCC) ) #1 SMP PREEMPT Wed Dec 31 14:42:53 PST 2014',
},
});
t.true(isWsl());
delete process.env.__IS_WSL_TEST__;
Object.defineProperty(process, 'platform', {value: originalPlatform});
});
test('inside WSL 2', async t => {
process.env.__IS_WSL_TEST__ = true;
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', {value: 'linux'});
const isWsl = await esmock('./index.js', {
fs: {
readFileSync: () => 'Linux version 4.19.43-microsoft-standard (oe-user@oe-host) (gcc version 7.3.0 (GCC)) #1 SMP Mon May 20 19:35:22 UTC 2019',
},
});
t.true(isWsl());
delete process.env.__IS_WSL_TEST__;
Object.defineProperty(process, 'platform', {value: originalPlatform});
});
test('not inside WSL', async t => {
process.env.__IS_WSL_TEST__ = true;
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', {value: 'darwin'});
const {default: isWsl} = await requireFresh('./index.js');
t.false(isWsl());
delete process.env.__IS_WSL_TEST__;
Object.defineProperty(process, 'platform', {value: originalPlatform});
});
test('not inside WSL, but inside Linux', async t => {
process.env.__IS_WSL_TEST__ = true;
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', {value: 'linux'});
const isWsl = await esmock('./index.js', {
fs: {
readFileSync: () => 'Linux version 4.19.43-standard (oe-user@oe-host) (gcc version 7.3.0 (GCC)) #1 SMP Mon May 20 19:35:22 UTC 2019',
},
os: {
release: () => '',
},
});
t.false(isWsl());
delete process.env.__IS_WSL_TEST__;
Object.defineProperty(process, 'platform', {value: originalPlatform});
});
test('inside WSL, but inside container', async t => {
process.env.__IS_WSL_TEST__ = true;
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', {value: 'linux'});
const isWsl = await esmock('./index.js', {
fs: {
readFileSync: () => 'Linux version 4.19.43-microsoft-standard (oe-user@oe-host) (gcc version 7.3.0 (GCC)) #1 SMP Mon May 20 19:35:22 UTC 2019',
},
'is-inside-container': () => true,
os: {
release: () => 'microsoft',
},
});
t.false(isWsl());
delete process.env.__IS_WSL_TEST__;
Object.defineProperty(process, 'platform', {value: originalPlatform});
});