Skip to content

Commit

Permalink
Update tests to include node
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMartinez committed Nov 9, 2023
1 parent 1589e39 commit 36b7ab3
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 13 deletions.

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

7 changes: 7 additions & 0 deletions test-fixtures/bundle-app-browser-map.js.map

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
(() => {
// output/Effect.Console/foreign.js
var log = function(s) {
Expand Down
16 changes: 16 additions & 0 deletions test-fixtures/bundle-app-node-map.js

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

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

15 changes: 15 additions & 0 deletions test-fixtures/bundle-app-node.js
Original file line number Diff line number Diff line change
@@ -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}");

// <stdin>
main();
14 changes: 12 additions & 2 deletions test/Prelude.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions test/Spago/Bundle.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 36b7ab3

Please sign in to comment.