#Testing with gleam + javascript

1 messages · Page 1 of 1 (latest)

dark elbow
#

I am experimenting with gleam in a javascript app. I am using the npm packages vite-gleam and ts-gleam for that (but I hope/think that should not matter for the sake of gleam test?)

so I have this directory setup:

tree . --gitignore
.
├── README.md
├── eslint.config.js
├── gleam.toml
├── manifest.toml
├── package.json
├── pnpm-lock.yaml
├── postcss.config.js
├── src
│   ├── app.css
│   ├── app.d.ts
│   ├── app.html
│   ├── g_kod.gleam
│   ├── g_kod_test.gleam
│   ├── index.test.ts
│   ├── lib
│   │   └── index.ts
│   └── routes
│       ├── +layout.svelte
│       ├── +layout.ts
│       └── +page.svelte
├── static
│   └── favicon.png
├── svelte.config.js
├── tailwind.config.ts
├── tsconfig.json
└── vite.config.ts

when I run gleam test I get:

gleam test
   Compiled in 0.01s
    Running g_kod_test.main
node:internal/fs/promises:945
  const result = await PromisePrototypeThen(
                 ^

Error: ENOENT: no such file or directory, scandir 'test'
    at async readdir (node:internal/fs/promises:945:18)
    at async gleamFiles (file:///Users/s0001325/repos/g-kod/build/dev/javascript/gleeunit/gleeunit_ffi.mjs:2:21)
    at async main (file:///Users/s0001325/repos/g-kod/build/dev/javascript/gleeunit/gleeunit_ffi.mjs:32:18) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'scandir',
  path: 'test'
}

Node.js v20.14.0

I am not really sure what's going on here.

first off, why is the node version printed? is node used to run the generated javascript code?

second, is there a certain directory structure that I am supposed to follow? is that why I see this error?

thanks!

ornate knot
#

gleam test runs the file test/{your_app}_test.gleam

#

you can see really that that is what the error is telling you too

#

Running g_kod_test.main

#

and then

ENOENT: no such file or directory, scandir 'test'

dark elbow
#

okay thanks, guessed as much. is that configureable somehow? is test/ the only place where it looks for tests? could it also be e.g. tests/?

ornate knot
#

if you wanna run a module you can do gleam run -m ...

#

gleam test does nothing magical except gleam run -m k_mod_test

dark elbow
#

thanks!

#

still not clear to me how gleam run -m g_kod_test.main automatically means test/g_kod_test.main instead of e.g. src/g_kod_test.main but I am sure it will click eventually

ornate knot
#

it doesnt automatically mean that

dark elbow
#

I guess that is part of gleeunit.main()

ornate knot
#

in fact if you had a file with the same name in both dir you would run into issues

dark elbow
#

sorry, I am a bit slow today it seems

ornate knot
#

no not at all, this stuff isnt documented anywhere

#

gleam consiers src/ and test/ both to be valid homes for modules, and they are not distinguished, when the project is built (locally) all compiled files are put in the same place so there is no difference between src/wibble.gleam and test/wibble.gleam, both would end up in the same built location with the same filename

dark elbow
ornate knot
#

the "magic" is that gleeunit will only import and discover tests from modules ending in test/**/*_test.gleam. those modules could live in s

#

heh yeah

#

this is a gleeunit thing not a gleam thing though, if you used a different test runner the rules could/would be different

dark elbow
#

got it! thanks for the thorough answers

ornate knot
#

happy to help

rose swallow
ornate knot
#

published packages dont publish the contents of test/

#

but for apps you can go wild