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

(cherry picked from commit f25a394)

# Conflicts:
#	.projen/deps.json
#	.projen/tasks.json
#	package.json
#	yarn.lock
  • Loading branch information
mrgrain committed Jan 10, 2024
1 parent 9a4c5b2 commit 365abb0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .projen/deps.json

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

11 changes: 11 additions & 0 deletions .projen/tasks.json

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

5 changes: 5 additions & 0 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
40 changes: 39 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 365abb0

Please sign in to comment.