DEV Community

Setting up a Svelte test environment

Daniel Irvine πŸ³οΈβ€πŸŒˆ on January 12, 2020

In this part, we’ll look at all the NPM packages and config that’s need to get a basic test environment running. By the end of it you’ll know enoug...
Collapse
 
jeffwscott profile image
Jeff Scott

I get this error when running "npm test".

Executing "e:<folder><app>\scripts\test":

npx rollup -c rollup.test.config.js -i

npx jasmine

events.js:174
throw er; // Unhandled 'error' event
^

Error: spawn e:<folder><app>\scripts\test ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR! Test failed. See above for more details.

I can run both the commands in the script file without scripty.
I don't have rollup running my production builds (I use webpack), so I don't really need the if statement in the script.

Any suggestions?

Collapse
 
d_ir profile image
Daniel Irvine πŸ³οΈβ€πŸŒˆ

Am I right in thinking you’re running on Windows? I took a look through the scripty Windows instructions but I’m not sure any of it applies to your situation, other than ensuring the file is in fact executable.

What happens if you run scripts/test directly from the command line?

Other than that I’m not sure what to suggest. If you can get a minimal reproduction onto GitHub/GitLab/etc I can take a look.

Collapse
 
matssom profile image
Mats Sommervold

I have this exact same issue. I cloned your repo to test if I did anything wrong, but I have the same issue with your code :/

Thread Thread
 
d_ir profile image
Daniel Irvine πŸ³οΈβ€πŸŒˆ

I wonder if package updates have broken something. I’ll find some time later today to take a look at this again.

Thread Thread
 
matssom profile image
Mats Sommervold

Thank you so much!

Thread Thread
 
eliseeaster profile image
eliseeaster

Are there any updates on this?

Collapse
 
ehrencrona profile image
Andreas Ehrencrona • Edited

In the repo, input: "spec/**/*.spec.js", has been replaced with just the name of the single test. If I put the regex back I get the error message Cannot use import statement outside a module when running the tests. There's no stack trace, so I'm not sure where this happens. Does anyone know a solution to this?

Collapse
 
jackryan1989 profile image
Jack Ryan

Hey Daniel,

Thanks for the fabulous post! I'm loving Svelte and this has been a super helpful and interesting post.

I have two things that I had to change to get the code (as it is up to this point in the series) running with an empty test component:

  1. I had to rename the test file to "test.spec.cjs" rather than just .js
  2. I had to point my "spec-files" to "*/.spec.js" in my jasmine.json file rather than "build/bundle-tests.js" as you have in your code. I suspect this is because we haven't 'rolled' anything up yet in the code?

Any insight on either of these items would be appreciated! Looking forward to the rest of the series.
Thanks!

Collapse
 
e01t profile image
E01T

Hello there,
Thanks for this great tutorial.
I have a problem, I get this error:

@ECHO OFF

if [ -z $1 ]; then
npx rollup -c rollup.test.config.js
else
npx rollup -c rollup.test.config.js -i $1
fi

if [ $? == 0 ]; then
npx jasmine
fi

Active code page: 1252
-z was unexpected at this time.
npm ERR! Test failed. See above for more details.

Any ideas?
What -z means by the way? Is it batch script?
I am using windows 7

Collapse
 
nikad profile image
nika-d

Hi Daniel!
Thank you a lot for this intro!
We built up a stack with this technologies:
Jest
Svelte 3
@testing-library/svelte
Typescript
Bootstrap 5
(rollup for bundling, not for tests)
node 16
In case anyone gets errors in their setup, here is a good thread to check: github.com/mihar-22/svelte-jester/...