From efabcda3d6ad9fefb7aeb8f320ad0795e555ed21 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 4 Oct 2023 20:01:20 -1000 Subject: [PATCH] test(static-module-record): add failing test for transform bug witnessed in browserfs --- .../test/fixtures/browserfs.js | 26 +++++++++++++++++++ .../test/test-static-module-record.js | 16 ++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 packages/static-module-record/test/fixtures/browserfs.js diff --git a/packages/static-module-record/test/fixtures/browserfs.js b/packages/static-module-record/test/fixtures/browserfs.js new file mode 100644 index 0000000000..2c0c437dad --- /dev/null +++ b/packages/static-module-record/test/fixtures/browserfs.js @@ -0,0 +1,26 @@ + +// src/ApiError.ts +var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => { + ErrorCode2[ErrorCode2["EPERM"] = 1] = "EPERM"; + ErrorCode2[ErrorCode2["ENOENT"] = 2] = "ENOENT"; + ErrorCode2[ErrorCode2["EIO"] = 5] = "EIO"; + ErrorCode2[ErrorCode2["EBADF"] = 9] = "EBADF"; + ErrorCode2[ErrorCode2["EACCES"] = 13] = "EACCES"; + ErrorCode2[ErrorCode2["EBUSY"] = 16] = "EBUSY"; + ErrorCode2[ErrorCode2["EEXIST"] = 17] = "EEXIST"; + ErrorCode2[ErrorCode2["ENOTDIR"] = 20] = "ENOTDIR"; + ErrorCode2[ErrorCode2["EISDIR"] = 21] = "EISDIR"; + ErrorCode2[ErrorCode2["EINVAL"] = 22] = "EINVAL"; + ErrorCode2[ErrorCode2["EFBIG"] = 27] = "EFBIG"; + ErrorCode2[ErrorCode2["ENOSPC"] = 28] = "ENOSPC"; + ErrorCode2[ErrorCode2["EROFS"] = 30] = "EROFS"; + ErrorCode2[ErrorCode2["ENOTEMPTY"] = 39] = "ENOTEMPTY"; + ErrorCode2[ErrorCode2["ENOTSUP"] = 95] = "ENOTSUP"; + return ErrorCode2; +})(ErrorCode || {}); + +ErrorCode[1]; + +export { + ErrorCode +} \ No newline at end of file diff --git a/packages/static-module-record/test/test-static-module-record.js b/packages/static-module-record/test/test-static-module-record.js index 035159786b..dab201835f 100644 --- a/packages/static-module-record/test/test-static-module-record.js +++ b/packages/static-module-record/test/test-static-module-record.js @@ -792,3 +792,19 @@ test('should handle package "immer" source', t => { setUseProxies: ['vn', true], }); }); + +// Regression test for https://github.com/jvilk/BrowserFS +test.failing('should handle package "browserfs" source', t => { + const { __syncModuleProgram__ } = new StaticModuleRecord( + readFixture('fixtures/browserfs.js'), + ); + t.notThrows(() => { + // This is throwing a ReferenceError for "ErrorCode" + eval(__syncModuleProgram__)({ + 'imports': () => {}, + 'liveVar': { + ErrorCode: () => {}, + } + }); + }); +});