vega / vega-lite

A concise grammar of interactive graphics, built on Vega.
https://vega.github.io/vega-lite/
BSD 3-Clause "New" or "Revised" License
4.56k stars 595 forks source link

Can't run tests locally #9375

Open joelostblom opened 2 weeks ago

joelostblom commented 2 weeks ago

Bug Description

If I clone the repo, navigate to the root dir, run yarn (or yarn --frozen-lockfile), and then try yarn jest examples/ I get the following:

vegalite ❯ yarn jest examples/                                                                                                                                                                                      
 FAIL  examples/examples.test.ts
  ● Test suite failed to run

    Cannot find module 'vega/build/vega-schema.json' from 'examples/examples.test.ts'

       5 | import path from 'path';
       6 | import {Spec as VgSpec} from 'vega';
    >  7 | import vgSchema from 'vega/build/vega-schema.json';
         | ^
       8 | import vlSchema from '../build/vega-lite-schema.json';
       9 | import {compile} from '../src/compile/compile';
      10 | import * as log from '../src/log';

      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
      at Object.<anonymous> (examples/examples.test.ts:7:1)

 PASS  examples/schema.test.ts

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        4.956 s
Ran all test suites matching /examples\//i.

I've also tried with yarn build and yarn build:only and don't see anything else helpful here https://github.com/vega/vega-lite/blob/main/CONTRIBUTING.md. yarn test also fails with the following message repeated 112 times:

 FAIL  test/encoding.test.ts
  ● Test suite failed to run

    Cannot find module 'vega' from 'src/scale.ts'

    Require stack:
      src/scale.ts
      src/compile/format.ts
      src/channeldef.ts
      test/encoding.test.ts

    However, Jest was able to find:
        './vega.schema.ts'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'mjs', 'cjs', 'jsx', 'ts', 'tsx', 'json', 'node'].

    See https://jestjs.io/docs/configuration#modulefileextensions-arraystring

    > 1 | import {
        | ^
      2 |   isObject,
      3 |   RangeEnum,
      4 |   ScaleBins,

      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
      at Object.<anonymous> (src/scale.ts:1:1)
      at Object.<anonymous> (src/compile/format.ts:16:1)
      at Object.<anonymous> (src/channeldef.ts:53:1)
      at Object.<anonymous> (test/encoding.test.ts:13:1)

Test Suites: 112 failed, 17 passed, 129 total
Tests:       118 passed, 118 total
Snapshots:   0 total
Time:        28.568 s
Ran all test suites matching /test\//i.

Checklist

domoritz commented 2 weeks ago

Did you link Vega by any chance? Try deleting your node modules folder.