From 84632571c7b516125b84e042e116a6d6bc76e20e Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 17 Sep 2021 16:10:43 -0700 Subject: Add test for "shuffle" function for lodash --- integration/scripts/browser.js | 2 ++ integration/snippets/lodash-regexp.js | 24 ++++++++++++++++++++++++ integration/snippets/package.json | 1 + integration/snippets/public/index.html | 17 +++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 integration/snippets/lodash-regexp.js (limited to 'integration') diff --git a/integration/scripts/browser.js b/integration/scripts/browser.js index a37e6e2a2..7fe9e8f4c 100644 --- a/integration/scripts/browser.js +++ b/integration/scripts/browser.js @@ -94,7 +94,9 @@ async function main() { "/multiple-imports.js", "/ts-fallback-rewrite-works.js", "/tsx-fallback-rewrite-works.js", + "/lodash-regexp.js", ]; + tests.reverse(); for (let test of tests) { await runPage(test); diff --git a/integration/snippets/lodash-regexp.js b/integration/snippets/lodash-regexp.js new file mode 100644 index 000000000..bc683e535 --- /dev/null +++ b/integration/snippets/lodash-regexp.js @@ -0,0 +1,24 @@ +import { shuffle } from "lodash"; + +// Lodash uses a variety of uncommon syntax (such as unicode escapes in regexp) +// so running it is a broad test of the parser, lexer, and printer +export function test() { + const foo = [1, 2, 3, 4, 6]; + const bar = shuffle(foo); + console.assert(bar !== foo); + console.assert(bar.length === foo.length); + bar.sort(); + foo.sort(); + for (let i = 0; i < bar.length; i++) { + console.assert(bar[i] === foo[i], "expected " + i + " to be " + foo[i]); + console.assert(typeof bar[i] === "number"); + console.assert(typeof foo[i] === "number"); + } + + return testDone(import.meta.url); +} + +// export function test() { +// const regexp = RegExp("['\u2019]", "g"); +// return testDone(import.meta.url); +// } diff --git a/integration/snippets/package.json b/integration/snippets/package.json index 8edbd79a1..1c0cb8b7b 100644 --- a/integration/snippets/package.json +++ b/integration/snippets/package.json @@ -4,6 +4,7 @@ "main": "index.js", "license": "MIT", "dependencies": { + "lodash": "^4.17.21", "react": "^17.0.2", "redux": "^4.1.1" } diff --git a/integration/snippets/public/index.html b/integration/snippets/public/index.html index 74a744a7d..5358fa423 100644 --- a/integration/snippets/public/index.html +++ b/integration/snippets/public/index.html @@ -46,6 +46,23 @@ return await testFunction(); }; + + if (globalThis.location.pathname.endsWith("-test")) { + globalThis.testDone = (path) => alert(`test ${path} success`); + globalThis.testFail = (path) => alert(`!test ${path} fail`); + runTest( + globalThis.location.pathname.substring( + 0, + location.pathname.length - "-test".length + ) + ).then( + () => {}, + (err) => { + console.error(err); + alert(err.toString()); + } + ); + } -- cgit v1.2.3