Skip to content

Commit

Permalink
chore: replace mock-fs with memfs that works in node20
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrain committed Nov 15, 2023
1 parent fe185c5 commit 2308845
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 39 deletions.
10 changes: 5 additions & 5 deletions .projen/deps.json

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

4 changes: 2 additions & 2 deletions .projen/tasks.json

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

4 changes: 2 additions & 2 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ const project = new typescript.TypeScriptProject({
'@actions/core',
'@actions/github',
'@types/commonmark',
'@types/mock-fs',
'@types/stream-json',
'@types/tar',
'@types/workerpool',
'mock-fs',
'fs-monkey',
'memfs',
'tar',
'ts-node',
],
Expand Down
6 changes: 3 additions & 3 deletions package.json

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

14 changes: 9 additions & 5 deletions test/jsii/assemblies.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { promises as fs } from 'node:fs';
import * as path from 'node:path';
import * as spec from '@jsii/spec';
import * as mockfs from 'mock-fs';
import { Volume } from 'memfs';

import { fakeAssembly } from './fake-assembly';
import { allTypeScriptSnippets } from '../../lib/jsii/assemblies';
import { SnippetParameters } from '../../lib/snippet';
import { TestJsiiModule, DUMMY_JSII_CONFIG } from '../testutil';
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { patchFs } = require('fs-monkey');

jest.setTimeout(30_000);

Expand Down Expand Up @@ -201,9 +203,11 @@ test('Fixture allows use of import statements', async () => {
});

test('Backwards compatibility with literate integ tests', async () => {
mockfs({
'/package/test/integ.example.lit.ts': '# Some literate source file',
});
const unpatch = patchFs(
Volume.fromJSON({
'/package/test/integ.example.lit.ts': '# Some literate source file',
}),
);

try {
const snippets = Array.from(
Expand Down Expand Up @@ -231,7 +235,7 @@ test('Backwards compatibility with literate integ tests', async () => {
path.normalize('/package/test'),
);
} finally {
mockfs.restore();
unpatch();
}
});

Expand Down
15 changes: 9 additions & 6 deletions test/rosetta.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as mockfs from 'mock-fs';

import { Volume } from 'memfs';
import { fakeAssembly } from './jsii/fake-assembly';
import { testSnippetLocation } from './testutil';
import {
Expand All @@ -12,6 +11,8 @@ import {
UnknownSnippetMode,
} from '../lib';
import { TargetLanguage } from '../lib/languages';
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { patchFs } = require('fs-monkey');

const SAMPLE_CODE: TypeScriptSnippet = {
visibleSource: 'callThisFunction();',
Expand Down Expand Up @@ -218,11 +219,13 @@ describe('Rosetta object with disclaimers', () => {
});

describe('with mocked filesystem', () => {
beforeEach(() => {
mockfs();
});
const vol = Volume.fromJSON({});
const unpatchFs = patchFs(vol);
afterEach(() => {
mockfs.restore();
vol.reset();
});
afterAll(() => {
unpatchFs();
});

const tablet = new LanguageTablet();
Expand Down
56 changes: 40 additions & 16 deletions yarn.lock

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

0 comments on commit 2308845

Please sign in to comment.