From 36b7ab3a8c57089d5c1cd14a2a415698eb505602 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 9 Nov 2023 15:34:16 -0600 Subject: [PATCH] Update tests to include node --- ...e-app-map.js => bundle-app-browser-map.js} | 3 +-- test-fixtures/bundle-app-browser-map.js.map | 7 ++++++ .../{bundle-app.js => bundle-app-browser.js} | 1 - test-fixtures/bundle-app-node-map.js | 16 ++++++++++++ ...-map.js.map => bundle-app-node-map.js.map} | 2 +- test-fixtures/bundle-app-node.js | 15 +++++++++++ test/Prelude.purs | 14 +++++++++-- test/Spago/Bundle.purs | 25 +++++++++++++------ 8 files changed, 70 insertions(+), 13 deletions(-) rename test-fixtures/{bundle-app-map.js => bundle-app-browser-map.js} (78%) create mode 100644 test-fixtures/bundle-app-browser-map.js.map rename test-fixtures/{bundle-app.js => bundle-app-browser.js} (92%) create mode 100755 test-fixtures/bundle-app-node-map.js rename test-fixtures/{bundle-app-map.js.map => bundle-app-node-map.js.map} (90%) create mode 100755 test-fixtures/bundle-app-node.js diff --git a/test-fixtures/bundle-app-map.js b/test-fixtures/bundle-app-browser-map.js similarity index 78% rename from test-fixtures/bundle-app-map.js rename to test-fixtures/bundle-app-browser-map.js index 1d0e283fc..7f0244068 100755 --- a/test-fixtures/bundle-app-map.js +++ b/test-fixtures/bundle-app-browser-map.js @@ -1,4 +1,3 @@ -#!/usr/bin/env node (() => { // output/Effect.Console/foreign.js var log = function(s) { @@ -13,4 +12,4 @@ // main(); })(); -//# sourceMappingURL=bundle-app-map.js.map +//# sourceMappingURL=bundle-app-browser-map.js.map diff --git a/test-fixtures/bundle-app-browser-map.js.map b/test-fixtures/bundle-app-browser-map.js.map new file mode 100644 index 000000000..2b20ce63d --- /dev/null +++ b/test-fixtures/bundle-app-browser-map.js.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["output/Effect.Console/foreign.js", "src/Main.purs", ""], + "sourcesContent": ["export const log = function (s) {\n return function () {\n console.log(s);\n };\n};\n\nexport const warn = function (s) {\n return function () {\n console.warn(s);\n };\n};\n\nexport const error = function (s) {\n return function () {\n console.error(s);\n };\n};\n\nexport const info = function (s) {\n return function () {\n console.info(s);\n };\n};\n\nexport const debug = function (s) {\n return function () {\n console.debug(s);\n };\n};\n\nexport const time = function (s) {\n return function () {\n console.time(s);\n };\n};\n\nexport const timeLog = function (s) {\n return function () {\n console.timeLog(s);\n };\n};\n\nexport const timeEnd = function (s) {\n return function () {\n console.timeEnd(s);\n };\n};\n\nexport const clear = function () {\n console.clear();\n};\n\nexport const group = function (s) {\n return function () {\n console.group(s);\n };\n};\n\nexport const groupCollapsed = function (s) {\n return function () {\n console.groupCollapsed(s);\n };\n};\n\nexport const groupEnd = function () {\n console.groupEnd();\n};\n", "module Main where\n\nimport Prelude\n\nimport Effect (Effect)\nimport Effect.Console (log)\n\nmain :: Effect Unit\nmain = do\n log \"\uD83C\uDF5D\"\n\n", "import { main } from './output/Main/index.js'; main();"], + "mappings": ";;AAAO,MAAM,MAAM,SAAU,GAAG;AAC9B,WAAO,WAAY;AACjB,cAAQ,IAAI,CAAC;AAAA,IACf;AAAA,EACF;;;ACGA,MAAA,OAAA,gBAAA,IAEM,WAAA;;;ACTyC,OAAK;", + "names": [] +} diff --git a/test-fixtures/bundle-app.js b/test-fixtures/bundle-app-browser.js similarity index 92% rename from test-fixtures/bundle-app.js rename to test-fixtures/bundle-app-browser.js index 2bc1320d3..fef3eca9a 100755 --- a/test-fixtures/bundle-app.js +++ b/test-fixtures/bundle-app-browser.js @@ -1,4 +1,3 @@ -#!/usr/bin/env node (() => { // output/Effect.Console/foreign.js var log = function(s) { diff --git a/test-fixtures/bundle-app-node-map.js b/test-fixtures/bundle-app-node-map.js new file mode 100755 index 000000000..9afe7d224 --- /dev/null +++ b/test-fixtures/bundle-app-node-map.js @@ -0,0 +1,16 @@ +#!/usr/bin/env node +import __module from 'module';import __path from 'path';import __url from 'url';const require = __module.createRequire(import.meta.url);const __dirname = __path.dirname(__url.fileURLToPath(import.meta.url));const __filename=new URL(import.meta.url).pathname + +// output/Effect.Console/foreign.js +var log = function(s) { + return function() { + console.log(s); + }; +}; + +// output/Main/index.js +var main = /* @__PURE__ */ log("\u{1F35D}"); + +// +main(); +//# sourceMappingURL=bundle-app-node-map.js.map diff --git a/test-fixtures/bundle-app-map.js.map b/test-fixtures/bundle-app-node-map.js.map similarity index 90% rename from test-fixtures/bundle-app-map.js.map rename to test-fixtures/bundle-app-node-map.js.map index e552335f2..50625c293 100644 --- a/test-fixtures/bundle-app-map.js.map +++ b/test-fixtures/bundle-app-node-map.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["output/Effect.Console/foreign.js", "src/Main.purs", ""], "sourcesContent": ["export const log = function (s) {\n return function () {\n console.log(s);\n };\n};\n\nexport const warn = function (s) {\n return function () {\n console.warn(s);\n };\n};\n\nexport const error = function (s) {\n return function () {\n console.error(s);\n };\n};\n\nexport const info = function (s) {\n return function () {\n console.info(s);\n };\n};\n\nexport const debug = function (s) {\n return function () {\n console.debug(s);\n };\n};\n\nexport const time = function (s) {\n return function () {\n console.time(s);\n };\n};\n\nexport const timeLog = function (s) {\n return function () {\n console.timeLog(s);\n };\n};\n\nexport const timeEnd = function (s) {\n return function () {\n console.timeEnd(s);\n };\n};\n\nexport const clear = function () {\n console.clear();\n};\n\nexport const group = function (s) {\n return function () {\n console.group(s);\n };\n};\n\nexport const groupCollapsed = function (s) {\n return function () {\n console.groupCollapsed(s);\n };\n};\n\nexport const groupEnd = function () {\n console.groupEnd();\n};\n", "module Main where\n\nimport Prelude\n\nimport Effect (Effect)\nimport Effect.Console (log)\n\nmain :: Effect Unit\nmain = do\n log \"\uD83C\uDF5D\"\n\n", "#!/usr/bin/env node\n\nimport { main } from './output/Main/index.js'; main();"], - "mappings": ";;;AAAO,MAAM,MAAM,SAAU,GAAG;AAC9B,WAAO,WAAY;AACjB,cAAQ,IAAI,CAAC;AAAA,IACf;AAAA,EACF;;;ACGA,MAAA,OAAA,gBAAA,IAEM,WAAA;;;ACPyC,OAAK;", + "mappings": ";;;;AAAO,IAAM,MAAM,SAAU,GAAG;AAC9B,SAAO,WAAY;AACjB,YAAQ,IAAI,CAAC;AAAA,EACf;AACF;;;ACGA,IAAA,OAAA,gBAAA,IAEM,WAAA;;;ACPyC,KAAK;", "names": [] } diff --git a/test-fixtures/bundle-app-node.js b/test-fixtures/bundle-app-node.js new file mode 100755 index 000000000..960ab5a3b --- /dev/null +++ b/test-fixtures/bundle-app-node.js @@ -0,0 +1,15 @@ +#!/usr/bin/env node +import __module from 'module';import __path from 'path';import __url from 'url';const require = __module.createRequire(import.meta.url);const __dirname = __path.dirname(__url.fileURLToPath(import.meta.url));const __filename=new URL(import.meta.url).pathname + +// output/Effect.Console/foreign.js +var log = function(s) { + return function() { + console.log(s); + }; +}; + +// output/Main/index.js +var main = /* @__PURE__ */ log("\u{1F35D}"); + +// +main(); diff --git a/test/Prelude.purs b/test/Prelude.purs index 7fde51cc1..b67ad22c0 100644 --- a/test/Prelude.purs +++ b/test/Prelude.purs @@ -80,13 +80,23 @@ shouldEqual -> m Unit shouldEqual v1 v2 = when (v1 /= v2) do - fail $ show v1 <> "\n\n≠\n\n" <> show v2 + fail $ show v1 <> "\n\n ≠\n\n " <> show v2 + +shouldEqualStr + :: forall m + . MonadThrow Error m + => String + -> String + -> m Unit +shouldEqualStr v1 v2 = + when (v1 /= v2) do + fail $ "\n=====\n" <> v1 <> "\n=====\n ≠\n=====\n " <> show v2 <> "\n=====\n" checkFixture :: String -> String -> Aff Unit checkFixture filepath fixturePath = do filecontent <- FS.readTextFile filepath fixturecontent <- FS.readTextFile fixturePath - filecontent `shouldEqual` fixturecontent + filecontent `shouldEqualStr` fixturecontent plusDependencies :: Array String -> Config -> Config plusDependencies deps config = config diff --git a/test/Spago/Bundle.purs b/test/Spago/Bundle.purs index f586167a6..a3b389b1d 100644 --- a/test/Spago/Bundle.purs +++ b/test/Spago/Bundle.purs @@ -9,10 +9,15 @@ spec :: Spec Unit spec = Spec.around withTempDir do Spec.describe "bundle" do - Spec.it "bundles into an app" \{ spago, fixture } -> do + Spec.it "bundles into an app (browser)" \{ spago, fixture } -> do spago [ "init" ] >>= shouldBeSuccess - spago [ "bundle", "-v", "--bundle-type", "app", "--outfile", "bundle-app.js" ] >>= shouldBeSuccess - checkFixture "bundle-app.js" (fixture "bundle-app.js") + spago [ "bundle", "-v", "--bundle-type", "app", "--outfile", "bundle-app-browser.js" ] >>= shouldBeSuccess + checkFixture "bundle-app-browser.js" (fixture "bundle-app-browser.js") + + Spec.it "bundles into an app (node)" \{ spago, fixture } -> do + spago [ "init" ] >>= shouldBeSuccess + spago [ "bundle", "-v", "--bundle-type", "app", "--outfile", "bundle-app-node.js", "--platform", "node" ] >>= shouldBeSuccess + checkFixture "bundle-app-node.js" (fixture "bundle-app-node.js") Spec.it "bundles into a module" \{ spago, fixture } -> do spago [ "init" ] >>= shouldBeSuccess @@ -23,11 +28,17 @@ spec = Spec.around withTempDir do spago [ "bundle", "--bundle-type=module", "--outfile", "bundle-module.js" ] >>= shouldBeSuccess checkFixture "bundle-module.js" (fixture "bundle-module.js") - Spec.it "bundles an app with source map" \{ spago, fixture } -> do + Spec.it "bundles an app with source map (browser)" \{ spago, fixture } -> do + spago [ "init" ] >>= shouldBeSuccess + spago [ "bundle", "-v", "--outfile", "bundle-app-browser-map.js", "--source-maps", "--bundle-type", "app" ] >>= shouldBeSuccess + checkFixture "bundle-app-browser-map.js" (fixture "bundle-app-browser-map.js") + checkFixture "bundle-app-browser-map.js.map" (fixture "bundle-app-browser-map.js.map") + + Spec.it "bundles an app with source map (node)" \{ spago, fixture } -> do spago [ "init" ] >>= shouldBeSuccess - spago [ "bundle", "-v", "--outfile", "bundle-app-map.js", "--source-maps", "--bundle-type", "app" ] >>= shouldBeSuccess - checkFixture "bundle-app-map.js" (fixture "bundle-app-map.js") - checkFixture "bundle-app-map.js.map" (fixture "bundle-app-map.js.map") + spago [ "bundle", "-v", "--outfile", "bundle-app-node-map.js", "--source-maps", "--bundle-type", "app", "--platform", "node" ] >>= shouldBeSuccess + checkFixture "bundle-app-node-map.js" (fixture "bundle-app-node-map.js") + checkFixture "bundle-app-node-map.js.map" (fixture "bundle-app-node-map.js.map") Spec.it "bundles a module with source map" \{ spago, fixture } -> do spago [ "init" ] >>= shouldBeSuccess