Skip to content

Commit

Permalink
feat: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed Feb 29, 2024
1 parent 4231372 commit 4a462aa
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 93 deletions.
1 change: 1 addition & 0 deletions .mocharc-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ require:
- intelli-espower-loader
full-trace: true
exit: true
parallel: false
1 change: 1 addition & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ require:
- intelli-espower-loader
full-trace: true
exit: true
parallel: false
5 changes: 5 additions & 0 deletions integration/fixtures/not-exist-lock-file/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"canvas": "2.9.0"
}
}
57 changes: 0 additions & 57 deletions integration/fixtures/utils/pids.js

This file was deleted.

29 changes: 17 additions & 12 deletions integration/index.2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ const {

describe('test/index.v2.test.js', () => {
let cwd;
let needClean = true;

afterEach(async () => {
await clean({ cwd });
if (process.platform === 'darwin') {
try {
await forceExitDaemon();
} catch (err) {
console.warn('force exit daemon error: %s', err.message);
if (needClean) {
await clean({ cwd, daemon: true });
if (process.platform === 'darwin') {
try {
await forceExitDaemon();
} catch (err) {
console.warn('force exit daemon error: %s', err.message);
}
} else {
await exitDaemon();
}
} else {
await exitDaemon();
}
needClean = true;
});

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

await execa.command(`umount -f ${nodeModulesDir}`);
await execa.command('killall -9 nydusd');
await setTimeoutPromise(20000);
assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14');
});
Expand All @@ -248,12 +251,14 @@ describe('test/index.v2.test.js', () => {
assert.strictEqual(dirs.filter(dir => dir.includes('esbuild')).length, 2);
await assert.doesNotReject(fs.stat(path.join(cwd, 'node_modules/esbuild')));
assert.strictEqual(require(path.join(cwd, 'node_modules', 'esbuild/package.json')).version, '0.15.14');
const nodeModulesDir = path.join(cwd, 'node_modules');

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

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

// nydusd has been killed
needClean = false;
});
});

Expand Down
12 changes: 8 additions & 4 deletions integration/workspaces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ describe('test/workspaces.test.js', () => {

it('should install lodash successfully', async () => {
cwd = path.join(__dirname, './fixtures/workspaces');
await clean({
cwd,
force: true,
});
try {
await clean({
cwd,
force: true,
});
} catch (e) {
console.warn('clean error: ', e);
}
await install({
nydusMode: 'FUSE',
cwd,
Expand Down
11 changes: 1 addition & 10 deletions packages/cli/lib/nydusd/nydusd_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ async function checkDaemon() {
// 优雅退出 nydusd daemon
async function exitDaemon() {
try {
await killDeamon();
await urllib.request(`${daemonUrl}/exit`, {
method: 'PUT',
socketPath,
dataType: 'json',
});
await killDeamon();
} catch (e) {
// ignore, nydusd quits with error, but it's ok
e.message = 'exit nydusd faield: ' + e.message;
Expand All @@ -170,15 +170,6 @@ async function forceExitDaemon() {
e.message = 'umount nydusd mnt failed: ' + e.message;
console.warn(e);
}

try {
await killDeamon();
await execa.command('killall -9 nydusd');
} catch (e) {
// ignore, nydusd quits with error, but it's ok
e.message = 'exit nydusd failed: ' + e.message;
console.warn(e);
}
}

async function mount(mountpoint, cwd, bootstrap = '') {
Expand Down
14 changes: 4 additions & 10 deletions packages/cli/test/package_lock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const path = require('node:path');
const fs = require('node:fs/promises');
const mm = require('mm');
const PackageLock = require('../lib/package_lock').PackageLock;
const { install } = require('../lib');
const httpclient = require('../lib/httpclient');
const { generatePackageLock } = require('../lib/util');
const nydusd = require('../lib/nydusd');
const downloadDependency = require('../lib/download_dependency');

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

it('should run all project installation scripts', async () => {
it('should generate package-lock.json', async () => {
fixture = path.join(__dirname, './fixtures/not-exist-lock-file');
const pkg = require(path.join(fixture, 'package.json'));
await install({
httpclient,
pkg,
cwd: fixture,
console: global.console,
});

await generatePackageLock(fixture);
await fs.stat(path.join(fixture, 'package-lock.json'));
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/test/scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ describe('test/scripts.test.js', () => {
mm(process.env, NYDUS_CSI_ROOT_ENV, 'true');
mm(process, 'cwd', () => fixtures);
mm(nydusd, 'startNydusFs', async () => { });
mm(util, 'ensureAccess', async () => { });
mm(util, 'storePackageLock', async () => { });
mm(downloadDependency, 'download', async () => {
return {
depsTree: [ 1 ],
Expand Down

0 comments on commit 4a462aa

Please sign in to comment.