Skip to content

Commit

Permalink
chore: replace mock-fs with memfs that works in node20 (#355)
Browse files Browse the repository at this point in the history
We are affected by this `mock-fs` bug:
tschaub/mock-fs#380
Seems like there is no activity on the repo recently, so we switch to a
new tool.

However `memfs` only works for the test case in `assemblies.test.ts`.
So we keep `mock-fs` for the `rosetta.test.ts` test cases.

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
mrgrain authored Nov 15, 2023
1 parent 73c7e21 commit f25a394
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 9 deletions.
8 changes: 8 additions & 0 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.

2 changes: 2 additions & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ const project = new typescript.TypeScriptProject({
'@types/stream-json',
'@types/tar',
'@types/workerpool',
'fs-monkey',
'memfs',
'mock-fs',
'tar',
'ts-node',
Expand Down
4 changes: 3 additions & 1 deletion 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
38 changes: 37 additions & 1 deletion yarn.lock

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

0 comments on commit f25a394

Please sign in to comment.