git.iko.soy/rowtype-yoga/purescript-backend-optimizer
on main help sign in
Use shell in test spawn (#51)

* Use shell in test spawn * Add attributes for snapshots * Use file url

commit851e258b48e5c0cee7af413f595b3f286b23fa4e authorNathan Faubion <natefaubion@users.noreply.github.com> dateMon 8 May 2023, 12:21 (3 years ago) parent5f1fd24
4 files changed+15−4
backend-es/test/Main.purs+1−1 backend-es/test/Utils.js+8−1 backend-es/test/Utils.purs+5−2 backend-es/test/snapshots-out/.gitattributes+1
backend-es/test/Main.purs+1−1
@@ -77,7 +77,7 @@ main = do
7777runSnapshotTests :: TestArgs -> Aff Unit
7878runSnapshotTests { accept, filter } = do
7979 liftEffect $ Process.chdir $ Path.concat [ "backend-es", "test", "snapshots" ]
80− spawnFromParent "spago" [ "build", "-u", "-g corefn" ]
80+ spawnFromParent "spago" [ "build -u \"-g corefn\"" ]
8181 snapshotDir <- liftEffect Process.cwd
8282 snapshotPaths <- expandGlobsCwd [ "Snapshot.*.purs" ]
8383 outputRef <- liftEffect $ Ref.new Map.empty
backend-es/test/Utils.js+8−1
@@ -1,6 +1,13 @@
1+import { spawn } from "child_process";
2+import { pathToFileURL } from "url";
3+
14export const loadModuleMainImpl = onError => onSuccessMain => onSuccess => path => () => {
2− import(path).then(
5+ import(pathToFileURL(path)).then(
36 mod => mod.main ? onSuccessMain(mod.main)() : onSuccess(),
47 err => onError(err)()
58 );
69}
10+
11+export const spawnImpl = cmd => args => () => {
12+ return spawn(cmd, args, { shell: true, stdio: "inherit" });
13+}
backend-es/test/Utils.purs+5−2
@@ -10,7 +10,7 @@ import Effect.Aff (Aff, Error, effectCanceler, error, makeAff, throwError)
1010import Effect.Class (liftEffect)
1111import Node.Buffer (Buffer, freeze)
1212import Node.Buffer.Immutable as ImmutableBuffer
13−import Node.ChildProcess (ExecResult, Exit(..), defaultExecOptions, defaultSpawnOptions, inherit)
13+import Node.ChildProcess (ChildProcess, ExecResult, Exit(..), defaultExecOptions)
1414import Node.ChildProcess as ChildProcess
1515import Node.Encoding (Encoding(..))
1616import Node.FS.Aff as FS
@@ -24,7 +24,7 @@ import Node.Stream as Stream
2424
2525spawnFromParent :: String -> Array String -> Aff Unit
2626spawnFromParent command args = makeAff \k -> do
27− childProc <- ChildProcess.spawn command args defaultSpawnOptions { stdio = inherit }
27+ childProc <- spawnImpl command args
2828 ChildProcess.onExit childProc case _ of
2929 Normally code
3030 | code > 0 -> Process.exit code
@@ -47,6 +47,9 @@ bufferToUTF8 = liftEffect <<< map (ImmutableBuffer.toString UTF8) <<< freeze
4747mkdirp :: FilePath -> Aff Unit
4848mkdirp path = FS.mkdir' path { recursive: true, mode: mkPerms Perms.all Perms.all Perms.all }
4949
50+-- This is needed because node-child-process is missing the "shell" option.
51+foreign import spawnImpl :: String -> Array String -> Effect ChildProcess
52+
5053foreign import loadModuleMainImpl :: (Error -> Effect Unit) -> (Effect Unit -> Effect Unit) -> Effect Unit -> FilePath -> Effect Unit
5154
5255loadModuleMain :: FilePath -> Aff (Maybe (Effect Unit))
backend-es/test/snapshots-out/.gitattributesnew file+1
@@ -0,0 +1 @@
1+*.js -merge -text