Skip to content

Commit

Permalink
Replace mock-fs with memfs + fs-monkey
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Aug 9, 2023
1 parent a3da2bf commit 723db6c
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 14 deletions.
124 changes: 114 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -97,8 +97,9 @@
"eslint-plugin-ava": "14.0.0",
"eslint-plugin-import": "2.28.0",
"eslint-plugin-prettier": "5.0.0",
"fs-monkey": "1.0.4",
"knip": "2.19.1",
"mock-fs": "5.2.0",
"memfs": "4.2.1",
"mock-stdio": "1.0.3",
"nock": "13.3.2",
"prettier": "3.0.1",
Expand Down
18 changes: 15 additions & 3 deletions test/npm.js
@@ -1,11 +1,21 @@
import path from 'node:path';
import { patchFs } from 'fs-monkey';
import test from 'ava';
import sinon from 'sinon';
import mock from 'mock-fs';
import { vol } from 'memfs';
import npm from '../lib/plugin/npm/npm.js';
import { factory, runTasks } from './util/index.js';
import { getArgs } from './util/helpers.js';

const mockFs = volume => {
vol.fromJSON(volume);
const unpatch = patchFs(vol);
return () => {
vol.reset();
unpatch();
};
};

test('should return npm package url', t => {
const options = { npm: { name: 'my-cool-package' } };
const npmClient = factory(npm, { options });
Expand Down Expand Up @@ -315,7 +325,7 @@ test('should skip checks', async t => {
});

test('should publish to a different/scoped registry', async t => {
mock({
const resetFs = mockFs({
[path.resolve('package.json')]: JSON.stringify({
name: '@my-scope/my-pkg',
version: '1.0.0',
Expand Down Expand Up @@ -349,10 +359,11 @@ test('should publish to a different/scoped registry', async t => {
]);

exec.restore();
resetFs();
});

test('should not publish when `npm version` fails', async t => {
mock({
const resetFs = mockFs({
[path.resolve('package.json')]: JSON.stringify({
name: '@my-scope/my-pkg',
version: '1.0.0'
Expand Down Expand Up @@ -384,6 +395,7 @@ test('should not publish when `npm version` fails', async t => {
]);

exec.restore();
resetFs();
});

test('should add allow-same-version argument', async t => {
Expand Down

0 comments on commit 723db6c

Please sign in to comment.