diff options
author | 2023-06-05 20:38:03 -0400 | |
---|---|---|
committer | 2023-06-05 17:38:03 -0700 | |
commit | 17bca62df10008b2d252d5b63bd9b028e9fcd1c0 (patch) | |
tree | 72472482ae24851f9d9f6e491e84e0b33e249f3a | |
parent | 0c11762c310c2655fe5c3ecc60671c93934abdc3 (diff) | |
download | bun-17bca62df10008b2d252d5b63bd9b028e9fcd1c0.tar.gz bun-17bca62df10008b2d252d5b63bd9b028e9fcd1c0.tar.zst bun-17bca62df10008b2d252d5b63bd9b028e9fcd1c0.zip |
add a test for lodash-es (#3217)
* add bundling tests for lodash-es
* add isBuffer tests
-rw-r--r-- | test/bundler/bundler_edgecase.test.ts | 38 | ||||
-rw-r--r-- | test/bundler/bundler_npm.test.ts | 25 | ||||
-rwxr-xr-x | test/bundler/run-single-bundler-test.sh | 2 |
3 files changed, 64 insertions, 1 deletions
diff --git a/test/bundler/bundler_edgecase.test.ts b/test/bundler/bundler_edgecase.test.ts index 2d406fed1..9d15cd031 100644 --- a/test/bundler/bundler_edgecase.test.ts +++ b/test/bundler/bundler_edgecase.test.ts @@ -894,4 +894,42 @@ describe("bundler", () => { stdout: "it worked\nit worked\nit worked\nit worked", }, }); + itBundled("edgecase/IsBuffer1", { + files: { + "/entry.js": /* js */ ` + import isBuffer from 'lodash-es/isBuffer'; + if(isBuffer !== 1) throw 'fail'; + console.log('pass'); + `, + "/node_modules/lodash-es/isBuffer.js": /* js */ ` + var freeExports = typeof exports == 'object'; + // this is using the 'freeExports' variable but giving a predictable outcome + const isBuffer = freeExports ? 1 : 1; + export default isBuffer; + `, + }, + run: { + stdout: "pass", + }, + }); + itBundled("edgecase/IsBuffer2", { + files: { + "/entry.js": /* js */ ` + import isBuffer from 'lodash-es/isBuffer'; + if(isBuffer !== 1) throw 'fail'; + console.log('pass'); + `, + "/node_modules/lodash-es/isBuffer.js": /* js */ ` + var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; + var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; + + // this is using the 'freeExports' variable but giving a predictable outcome + const isBuffer = [freeExports, freeModule] ? 1 : 1; + export default isBuffer; + `, + }, + run: { + stdout: "pass", + }, + }); }); diff --git a/test/bundler/bundler_npm.test.ts b/test/bundler/bundler_npm.test.ts index c421912ed..327d68087 100644 --- a/test/bundler/bundler_npm.test.ts +++ b/test/bundler/bundler_npm.test.ts @@ -43,4 +43,29 @@ describe("bundler", () => { stdout: "<!DOCTYPE html><html><head></head><body><h1>Hello World</h1><p>This is an example.</p></body></html>", }, }); + itBundled("npm/LodashES", { + install: ["lodash-es"], + files: { + "/entry.ts": /* tsx */ ` + import { isEqual, isBuffer } from "lodash-es"; + + // https://github.com/oven-sh/bun/issues/3206 + if(!isEqual({a: 1}, {a: 1})) throw "error 1"; + if(isEqual({a: 1}, {a: 2})) throw "error 2"; + + // Uncomment when https://github.com/lodash/lodash/issues/5660 is fixed + // It prevents isBuffer from working at all since it evaluates to 'stubFalse' + // if(!isBuffer(Buffer.from("hello"))) throw "error 3"; + // if(isBuffer("hello")) throw "error 4"; + // if(isBuffer({})) throw "error 5"; + // if(isBuffer(new Uint8Array([1]))) throw "error 6"; + // if(isBuffer(new ArrayBuffer(1))) throw "error 7"; + + console.log('pass') + `, + }, + run: { + stdout: "pass", + }, + }); }); diff --git a/test/bundler/run-single-bundler-test.sh b/test/bundler/run-single-bundler-test.sh index 389e2a399..2f64242eb 100755 --- a/test/bundler/run-single-bundler-test.sh +++ b/test/bundler/run-single-bundler-test.sh @@ -30,7 +30,7 @@ fi export FORCE_COLOR=1 $BUN test bundler_ esbuild/ 2>&1 \ | perl -ne 'print unless /^\e\[0m$/' \ - | grep -v -P '\x1b\[0m\x1b\[33m-\x1b\[2m \x1b\[0m\x1b\[2mbundler' --text \ + | grep -v '\x1b\[0m\x1b\[33m-\x1b\[2m \x1b\[0m\x1b\[2mbundler' --text \ | grep -v ".test.ts:$" --text \ | tee /tmp/run-single-bundler-test.txt \ | grep "root:" -v --text |