Skip to content

Commit 185553e

Browse files
committed
feat: update test
1 parent 4231372 commit 185553e

File tree

11 files changed

+80
-104
lines changed

11 files changed

+80
-104
lines changed

.mocharc-integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ require:
1010
- intelli-espower-loader
1111
full-trace: true
1212
exit: true
13+
parallel: false

.mocharc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ require:
1010
- intelli-espower-loader
1111
full-trace: true
1212
exit: true
13+
parallel: false
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"canvas": "2.9.0"
4+
}
5+
}

integration/fixtures/utils/pids.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

integration/index.2.test.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,25 @@ describe('test/index.v2.test.js', () => {
2020
let cwd;
2121

2222
afterEach(async () => {
23-
await clean({ cwd });
23+
try {
24+
await clean({ cwd, daemon: true });
25+
} catch (e) {
26+
console.warn('clean error: ', e);
27+
}
2428
if (process.platform === 'darwin') {
2529
try {
2630
await forceExitDaemon();
2731
} catch (err) {
2832
console.warn('force exit daemon error: %s', err.message);
2933
}
3034
} else {
31-
await exitDaemon();
35+
try {
36+
await exitDaemon();
37+
} catch (err) {
38+
console.warn('exit daemon error: %s', err.message);
39+
}
3240
}
41+
3342
});
3443

3544
describe('update', () => {
@@ -223,9 +232,8 @@ describe('test/index.v2.test.js', () => {
223232
assert.strictEqual(dirs.filter(dir => dir.includes('esbuild')).length, 2);
224233
await assert.doesNotReject(fs.stat(path.join(cwd, 'node_modules/esbuild')));
225234
assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14');
226-
const nodeModulesDir = path.join(cwd, 'node_modules');
227235

228-
await execa.command(`umount -f ${nodeModulesDir}`);
236+
await execa.command('killall -9 nydusd');
229237
await setTimeoutPromise(20000);
230238
assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14');
231239
});
@@ -248,9 +256,8 @@ describe('test/index.v2.test.js', () => {
248256
assert.strictEqual(dirs.filter(dir => dir.includes('esbuild')).length, 2);
249257
await assert.doesNotReject(fs.stat(path.join(cwd, 'node_modules/esbuild')));
250258
assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14');
251-
const nodeModulesDir = path.join(cwd, 'node_modules');
252259

253-
await execa.command(`umount -f ${nodeModulesDir}`);
260+
await execa.command('killall -9 nydusd');
254261
await setTimeoutPromise(20000);
255262

256263
await assert.rejects(fs.stat(path.join(cwd, 'node_modules', 'esbuild/package.json')));

integration/index.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ const {
1616
describe('test/index.test.js', () => {
1717
let fixture;
1818
afterEach(async () => {
19-
await clean({
20-
cwd: fixture,
21-
});
19+
try {
20+
await clean({
21+
cwd: fixture,
22+
});
23+
} catch (e) {
24+
console.warn('clean error: ', e);
25+
}
2226
if (process.platform === 'darwin') {
2327
await forceExitDaemon();
2428
} else {

integration/workspaces.test.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ const {
1212
forceExitDaemon,
1313
} = require('@cnpmjs/rapid/lib/nydusd/nydusd_api');
1414

15-
describe('test/workspaces.test.js', () => {
15+
describe.only('test/workspaces.test.js', () => {
1616
let cwd;
1717

1818
it('should install lodash successfully', async () => {
1919
cwd = path.join(__dirname, './fixtures/workspaces');
20-
await clean({
21-
cwd,
22-
force: true,
23-
});
20+
try {
21+
await clean({
22+
cwd,
23+
force: true,
24+
});
25+
} catch (e) {
26+
console.warn('clean error: ', e);
27+
}
2428
await install({
2529
nydusMode: 'FUSE',
2630
cwd,

packages/cli/lib/nydusd/nydusd_api.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ async function checkDaemon() {
145145
// 优雅退出 nydusd daemon
146146
async function exitDaemon() {
147147
try {
148-
await killDeamon();
149148
await urllib.request(`${daemonUrl}/exit`, {
150149
method: 'PUT',
151150
socketPath,
152151
dataType: 'json',
153152
});
153+
await killDeamon();
154154
} catch (e) {
155155
// ignore, nydusd quits with error, but it's ok
156156
e.message = 'exit nydusd faield: ' + e.message;
@@ -170,15 +170,6 @@ async function forceExitDaemon() {
170170
e.message = 'umount nydusd mnt failed: ' + e.message;
171171
console.warn(e);
172172
}
173-
174-
try {
175-
await killDeamon();
176-
await execa.command('killall -9 nydusd');
177-
} catch (e) {
178-
// ignore, nydusd quits with error, but it's ok
179-
e.message = 'exit nydusd failed: ' + e.message;
180-
console.warn(e);
181-
}
182173
}
183174

184175
async function mount(mountpoint, cwd, bootstrap = '') {

packages/cli/test/package_lock.test.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const path = require('node:path');
55
const fs = require('node:fs/promises');
66
const mm = require('mm');
77
const PackageLock = require('../lib/package_lock').PackageLock;
8-
const { install } = require('../lib');
9-
const httpclient = require('../lib/httpclient');
8+
const { generatePackageLock } = require('../lib/util');
109
const nydusd = require('../lib/nydusd');
1110
const downloadDependency = require('../lib/download_dependency');
1211

@@ -68,15 +67,10 @@ describe('test/package_lock.test.js', () => {
6867
mm.restore();
6968
});
7069

71-
it('should run all project installation scripts', async () => {
70+
it('should generate package-lock.json', async () => {
7271
fixture = path.join(__dirname, './fixtures/not-exist-lock-file');
73-
const pkg = require(path.join(fixture, 'package.json'));
74-
await install({
75-
httpclient,
76-
pkg,
77-
cwd: fixture,
78-
console: global.console,
79-
});
72+
73+
await generatePackageLock(fixture);
8074
await fs.stat(path.join(fixture, 'package-lock.json'));
8175
});
8276
});

packages/cli/test/scripts.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ describe('test/scripts.test.js', () => {
163163
mm(process.env, NYDUS_CSI_ROOT_ENV, 'true');
164164
mm(process, 'cwd', () => fixtures);
165165
mm(nydusd, 'startNydusFs', async () => { });
166+
mm(util, 'ensureAccess', async () => { });
167+
mm(util, 'storePackageLock', async () => { });
166168
mm(downloadDependency, 'download', async () => {
167169
return {
168170
depsTree: [ 1 ],

0 commit comments

Comments
 (0)