stencil-community / stencil-app-starter

Minimal starter project for building web components with Stencil
https://github.com/ionic-team/stencil
MIT License
320 stars 102 forks source link

`npm run test` fails to run #28

Closed d2s closed 6 years ago

d2s commented 6 years ago

Resources:

Stencil version: (npm list @stencil/core output below):

@stencil/starter@0.0.1 /[… filesystem path removed …]/GitHub/ionic-team/stencil-app-starter
└── @stencil/core@0.0.7-2

I'm submitting a ... (check one with "x") [x] bug report [ ] feature request [ ] support request

Current behavior:

Tests fail to run by default, when running npm run test command.

Expected behavior:

Default tests should run without errors.

Steps to reproduce:

Related code:

npm run test

> @stencil/starter@0.0.1 test /[… filesystem path removed …]/GitHub/ionic-team/stencil-app-starter
> jest --no-cache

 FAIL  src/components/my-name/my-name.spec.ts
  ● Test suite failed to run

    ReferenceError: expect is not defined

      at Object.<anonymous> (node_modules/@stencil/core/testing/index.js:4669:1)
      at Module._compile (module.js:635:30)
      at Object.Module._extensions..js (module.js:646:10)
      at Module.load (module.js:554:32)
      at tryModuleLoad (module.js:497:12)
      at Function.Module._load (module.js:489:3)
      at Module.require (module.js:579:17)
      at require (internal/module.js:11:18)
      at Object.<anonymous> (node_modules/@stencil/core/testing/jest.preprocessor.js:3:15)
      at Module._compile (module.js:635:30)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.122s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @stencil/starter@0.0.1 test: `jest --no-cache`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @stencil/starter@0.0.1 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/d2s/.npm/_logs/2017-11-09T14_45_21_323Z-debug.log

Other information:

Using latest Node.js LTS version (via nvm, installed with the instructions available at a Gist page). Computer itself is running a recent version of macOS.

❯ nvm ls
->       v8.9.0

❯ node --version
v8.9.0

❯ npm --version
5.5.1
rbeen commented 6 years ago

I have the exact same issue, haven't had time to dive deeper into it yet. Did you find a solution?

d2s commented 6 years ago

@rbeen No, I did not have time or energy to debug the issue.

It is (probably) caused by the changed internal structure of stencil core’s tests: https://github.com/ionic-team/stencil/tree/master/src/testing

Looking quickly, https://github.com/ionic-team/stencil/issues/272 issue might be related to this in some way, but not really sure about that. Anyway, Stencil core team should look at the issue in their side of things.

kensodemann commented 6 years ago

The error you are reporting looks more like this one: https://github.com/ionic-team/stencil/issues/288

I do not know if there has been a release with that fix in it or not yet.

d2s commented 6 years ago

@kensodemann @rbeen v0.0.8-0 was tagged as released 3 days ago.

package.json of the stencil-app-starter repository is pointing to a "next" version:

  "dependencies": {
    "@stencil/core": "next",
    "@stencil/router": "latest"
  },

When user runs npm update on their local project directory, npm downloads the latest version of the Stencil core package.

❯ npm update
+ @types/jest@21.1.6
+ @stencil/core@0.0.8-0
removed 3 packages and updated 3 packages in 8.987s

After the update command, tests should now be able to finish properly.

❯ npm run test

> learning-stencil@0.0.3 test /[… path removed …]/learning-stencil
> jest --no-cache

 PASS  src/components/my-name/my-name.spec.ts
  my-name
    ✓ should build (4ms)
    rendering
      ✓ should work without parameters (1156ms)
      ✓ should work a first name (7ms)
      ✓ should work with a last name (3ms)
      ✓ should work with both a first and a list name (3ms)

Test Suites: 1 passed, 1 total
Tests:       5 passed, 5 total
Snapshots:   0 total
Time:        3.726s
Ran all test suites.

In overall, it looks that the issue is almost fixed.

People just have to run the update command manually, if they have older version of the core package installed on the project’s local npm dependencies.

Remaining part of the issue is that this starter project has outdated package-lock.json version from one month ago. If that is not updated, some people will keep having issues with the Stencil core package.

jgw96 commented 6 years ago

Hello all! This has since been fixed and I can no longer reproduce in the latest version of this starter. Thanks for using Stencil!