Fork me on GitHub
#shadow-cljs
<
2022-12-26
>
DrLjótsson00:12:17

I want to run my tests in node.js, but there are a couple of namespaces that include libraries that are not available in node.js. Can I create new namespaces that "shadow" these namespaces and are only included in the :target :node-js build? I tried adding the :deps {:aliases [ ... ]} key for that build only, with a deps alias that includes a path with those namespaces but :deps only seems to work on the global level. Any other suggestions?

thheller06:12:48

the best option is to remove those namespaces from the build entirely. there are ways to do this usually, without any config and other hacks. just moving some code around and only requiring them when actually needed but not in tests

thheller06:12:44

otherwise there is the option to :build-options {:ns-aliases {the.ns.you.dont.want the.replacement}} in the build config

DrLjótsson19:12:42

Thanks @thheller ! I have actually started to move the code around as you suggested. But thanks for the :ns-aliases tip, could come in handy in the future.

pez16:12:18

Hello, I'm trying to use https://github.com/microsoft/vscode-test to e2e test a VS Code extension built with shadow-cljs. vscode-test exposes a runTests function that launches VS Code. To runTests I provide an argument pointing at a module exporting a run function that is responsible for running the actual tests. I'm using the :node-script target to build a script that both calls runTest and exports a run function from where I am calling cljs.test/run-all-tests. I run into a strange error when the extension has started complaining about swap! not being defined for cljs.core/Atom. Adding the log to a reply....

pez16:12:49

npm run integration-test                 

> [email protected] integration-test
> node ./out/integration/run-tests.js

Found existing install in /Users/pez/Projects/joyride/.vscode-test/vscode-darwin-arm64-insiders. Skipping download
[1226/165401.528660:ERROR:(42)] opendir /Users/pez/Projects/joyride/.vscode-test/user-data/Crashpad/attachments/c145ce85-3e2d-4bb8-aa46-35db68754304: No such file or directory (2)
[main 2022-12-26T15:54:01.830Z] update#ctor - updates are disabled by the environment
Electron sandbox mode is enabled!
2022-12-26 16:54:02.294 Code - Insiders Helper (Renderer)[63693:27845893] CoreText note: Client requested name ".NewYork-Regular", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].
2022-12-26 16:54:02.294 Code - Insiders Helper (Renderer)[63693:27845893] CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug.
Loading development extension at /Users/pez/Projects/joyride
[main 2022-12-26T15:54:04.111Z] UtilityProcess<1>: Creating new...
[main 2022-12-26T15:54:04.112Z] UtilityProcess<1>: received spawn event.
Joyride activate START
Joyride activate END
shadow-cljs - #8 ready!
Hello World, from my-main in user_activate.cljs script
SHADOW import error /Users/pez/Projects/joyride/out/integration/js/cljs-runtime/cljs.pprint.js
Error: No protocol method ISwap.-swap! defined for type cljs.core/Atom: [object Object]
    at Object.cljs$core$missing_protocol [as missing_protocol] (/Users/pez/Projects/joyride/out/integration/js/cljs-runtime/cljs/core.cljs:320:3)
    at G__44580__4 (/Users/pez/Projects/joyride/out/integration/js/cljs-runtime/cljs/core.cljs:869:1)
    at G__44580 (/Users/pez/Projects/joyride/out/integration/js/cljs-runtime/cljs.core.js:3695:20)
    at Function.cljs$core$IFn$_invoke$arity$4 (/Users/pez/Projects/joyride/out/integration/js/cljs-runtime/cljs/core.cljs:869:1)
    at Object.cljs$core$_swap_BANG_ [as _swap_BANG_] (/Users/pez/Projects/joyride/out/integration/js/cljs-runtime/cljs/core.cljs:869:1)
    at Function.cljs$core$IFn$_invoke$arity$4 (/Users/pez/Projects/joyride/out/integration/js/cljs-runtime/cljs/core.cljs:4560:7)
    at Object.cljs$core$IMultiFn$_add_method$arity$3 (/Users/pez/Projects/joyride/out/js/cljs-runtime/cljs/core.cljs:11330:1)
    at /Users/pez/Projects/joyride/out/integration/js/cljs-runtime/cljs/pprint.cljs:268:1
    at global.SHADOW_IMPORT (/Users/pez/Projects/joyride/out/integration/run-tests.js:64:44)
    at /Users/pez/Projects/joyride/out/integration/run-tests.js:1695:1
    at Object.<anonymous> (/Users/pez/Projects/joyride/out/integration/run-tests.js:1701:3)
    at Module._compile (node:internal/modules/cjs/loader:1165:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1220:10)
    at Module.load (node:internal/modules/cjs/loader:1035:32)
    at Module._load (node:internal/modules/cjs/loader:876:12)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
    at Function.l._load (/Users/pez/Projects/joyride/.vscode-test/vscode-darwin-arm64-insiders/Visual Studio Code - )
    at Function.w._load (/Users/pez/Projects/joyride/.vscode-test/vscode-darwin-arm64-insiders/Visual Studio Code - )
    at Function.v._load (/Users/pez/Projects/joyride/.vscode-test/vscode-darwin-arm64-insiders/Visual Studio Code - )
    at Module.require (node:internal/modules/cjs/loader:1059:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Function.r [as __$__nodeRequire] (/Users/pez/Projects/joyride/.vscode-test/vscode-darwin-arm64-insiders/Visual Studio Code - )
    at d.pb (/Users/pez/Projects/joyride/.vscode-test/vscode-darwin-arm64-insiders/Visual Studio Code - )
    at d.jb (/Users/pez/Projects/joyride/.vscode-test/vscode-darwin-arm64-insiders/Visual Studio Code - )
    at d.$extensionTestsExecute (/Users/pez/Projects/joyride/.vscode-test/vscode-darwin-arm64-insiders/Visual Studio Code - )
[main 2022-12-26T15:54:05.014Z] UtilityProcess<1>: Waiting for extension host with pid 65161 to exit.
[main 2022-12-26T15:54:05.039Z] UtilityProcess<1>: received exit event with code 0.
[main 2022-12-26T15:54:05.039Z] Extension host with pid 65161 exited with code: 0, signal: .
Exit code:   1
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Failed".
So, right before the SHADOW import error I see println messages from my extension and from shadow, indicating that it starts OK. It all works fine if starting VS Code with this extension installed. I don't understand why this way of starting things would trigger this particular error...

pez16:12:47

Not expecting anyone else to understand it either, mainly looking for ideas on what to try to isolate things a bit.

pez16:12:03

cc: @U04V15CAJ who at least has some context. 😃

thheller17:12:32

my guess is that the extension is loaded twice. or rather cljs.core being loaded twice

thheller17:12:31

[main 2022-12-26T15:54:04.111Z] UtilityProcess<1>: Creating new... don't know what it is creating but the error happens when cljs.core is loaded twice, because the protocol is redefined and then things go weird

pez17:12:14

Thanks. Maybe it's because I have the testrunner run function in the same module that starts VS Code. I'll try to avoid that and see if it gets me to a new place.

pez18:12:25

Hmmm, no, it seems to be that the tests themselves are written in cljs and I am trying to run shadow twice or something. If I compile the tests using release I get rid of the error. Which is fine. However, it doesn't actually run the tests. There is only one in this test run, a failing one, yet:

% npx shadow-cljs release :integration-tests && npm run integration-test
shadow-cljs - config: /Users/pez/Projects/joyride/shadow-cljs.edn
shadow-cljs - connected to server
[:integration-tests] Compiling ...
[:integration-tests] Build completed. (53 files, 1 compiled, 0 warnings, 2.65s)



> [email protected] integration-test
> node ./test/vscode-test-runner/runTests.js

Found existing install in /Users/pez/Projects/joyride/.vscode-test/vscode-darwin-arm64-insiders. Skipping download
[main 2022-12-26T18:01:55.407Z] update#ctor - updates are disabled by the environment
Electron sandbox mode is enabled!
2022-12-26 19:01:55.976 Code - Insiders Helper (Renderer)[23999:28228777] CoreText note: Client requested name ".NewYork-Regular", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].
2022-12-26 19:01:55.976 Code - Insiders Helper (Renderer)[23999:28228777] CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug.
Loading development extension at /Users/pez/Projects/joyride
[main 2022-12-26T18:01:57.860Z] UtilityProcess<1>: Creating new...
[main 2022-12-26T18:01:57.862Z] UtilityProcess<1>: received spawn event.
Joyride activate START
Joyride activate END
shadow-cljs - #17 ready!
Hello World, from my-main in user_activate.cljs script

Testing integration.js-require

Ran 0 tests containing 0 assertions.
0 failures, 0 errors.
[main 2022-12-26T18:01:58.663Z] UtilityProcess<1>: Waiting for extension host with pid 25469 to exit.
[main 2022-12-26T18:01:58.681Z] UtilityProcess<1>: received exit event with code 0.
[main 2022-12-26T18:01:58.681Z] Extension host with pid 25469 exited with code: 0, signal: .
Exit code:   0
Done

~/Projects/joyride(pez/test-runner|✚5…) % 

thheller06:12:04

are the tests loaded while also loading a debug version of the extension itself?

thheller06:12:10

if they run the same context that won't work

thheller06:12:24

can't have two debug builds running at the same time

pez08:12:54

In that last attempt I loaded the tests in a release build, and the extension itself was a debug build. I now tried starting from clean and release compiling both targets before running the tests. Still no test results. Interestingly if I use cljs.test/run-all-tests it reports Testing tests for promesa and all other libraries used which has tests, including my failing test. And still reports that 0 tests and assertions are run. I'll keep digging...

thheller10:12:25

if they are async tests do you use async correctly? otherwise the test runner will just exit since it doesn't know that tests are still running

thheller11:12:40

but again the most likely problem here is loading two builds into one environment. regardless of combination this just won't work if these are not isolated contexts

thheller11:12:14

but I do not know enough about either vscode and vscode-test to make any meaningful suggestions

pez11:12:02

You have made amazingly meaningful suggestions so far. 😃 But, indeed, lots of moving parts here. I'm trying to do this with Joyride itself now instead. That's also gets a bit of a mind-fuck, but I can run the tests on the debug build (with the the debug build) so much faster feedback.

denik20:12:47

@thheller happy holidays! I have a very macro-heavy project. Essentially there’s a whole other compiler running inside macros rewriting code. This seems to lead to shadow-cljs to recompile all code regardless of whether the code inside the macro has changed (output likely changes on each eval because of gensyms etc) leading to excessive compilation times (> 10 secs for about ~1000 LoC of code). Is there a way to tell shadow to use cached output for macros as long as the body of the macro expression has not changed?

thheller06:12:23

that is the default, unless you manually turned off caching or so

thheller06:12:51

or using :dev/always true in the ns meta will have the same effect

thheller06:12:03

or the macro having side effect and writing files the compiler sees

thheller06:12:32

otherwise it only considers files that are relevant to the compiled file (ie. its requires)

denik21:12:35

Okay thanks for the context