Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vitest - Runtime error: TypeError: Cannot set properties of undefined (setting '0')​​ #3034

Closed
davidwhitney opened this issue Jul 24, 2022 · 3 comments

Comments

@davidwhitney
Copy link

davidwhitney commented Jul 24, 2022

Issue description or question

Previously working (~1 week ago) tests using vitest (both 0.18.0 and 0.19.0) seem to now fail with the message:

Runtime error: TypeError: Cannot set properties of undefined (setting '0')​​

In a different repo, I noticed setting '0' was replaced with the sequential order of the tests in the file (setting 1000001 for the first test 1000002 for the second etc). Upgraded vitest to latest (0.19.0) and force updated Wallaby core to verify, across two different machines.

Example failing repo - main branch here - /~https://github.com/ably-labs/react-hooks

Tests all pass using npx vitest run

Wallaby diagnostics report

{
  editorVersion: '1.69.1',
  pluginVersion: '1.0.345',
  editorType: 'VSCode',
  osVersion: 'win32 10.0.22622',
  nodeVersion: 'v16.13.0',
  coreVersion: '1.0.1305',
  checksum: 'NmNkNWNkOTE2YWZmYzdmNWFjMGVhMTcwMDc3OTIwZmIsMTY2OTQyMDgwMDAwMCww',
  config: {
    diagnostics: {
      vitest: {
        file: {
          config: "import { defineConfig } from 'vitest/config'\r\n" +
            "import react from '@vitejs/plugin-react';\r\n" +
            '\r\n' +
            'export default defineConfig({  \r\n' +
            '  root: "src",\r\n' +
            '  plugins: [react()],\r\n' +
            '  test: {\r\n' +
            '    globals: true, \r\n' +
            "    environment: 'jsdom', \r\n" +
            '  },\r\n' +
            '})'
        },
        config: {
          allowOnly: true,
          watch: true,
          globals: true,
          environment: 'jsdom',
          threads: true,
          clearMocks: false,
          restoreMocks: false,
          mockReset: false,
          include: [ '**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}' ],
          exclude: [ '**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**' ],
          testTimeout: 5000,
          hookTimeout: 10000,
          teardownTimeout: 1000,
          isolate: true,
          watchExclude: [ '**/node_modules/**', '**/dist/**' ],
          forceRerunTriggers: [ '**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**' ],
          update: false,
          reporters: [ 'default' ],
          silent: false,
          ui: false,
          uiBase: '/__vitest__/',
          open: true,
          css: { include: [ {} ] },
          coverage: {
            enabled: false,
            clean: true,
            cleanOnRerun: false,
            reportsDirectory: 'C:/dev/ably-labs/react-hooks/src/coverage',
            excludeNodeModules: true,
            exclude: [
              'coverage/**',
              'dist/**',
              'packages/*/test{,s}/**',
              '**/*.d.ts',
              'cypress/**',
              'test{,s}/**',
              'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
              '**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
              '**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}',
              '**/__tests__/**',
              '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress}.config.{js,cjs,mjs,ts}',
              '**/.{eslint,mocha,prettier}rc.{js,cjs,yml}'
            ],
            reporter: [ 'text', 'html' ],
            allowExternal: false,
            extension: [
              '.js',  '.cjs',
              '.mjs', '.ts',
              '.tsx', '.jsx',
              '.vue', '.svelte'
            ],
            tempDirectory: 'C:/dev/ably-labs/react-hooks/src/coverage/tmp'
          },
          fakeTimers: { loopLimit: 10000, shouldClearNativeTimers: true, toFake: [ 'setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date' ] },
          maxConcurrency: 5,
          defines: {},
          root: 'C:/dev/ably-labs/react-hooks/src',
          deps: { inline: [ {}, {}, {}, {}, {}, {}, '@nuxt/test-utils' ] },
          snapshotOptions: { snapshotFormat: {}, updateSnapshot: 'new' },
          setupFiles: [],
          cache: { dir: 'C:/dev/ably-labs/react-hooks/src/node_modules/.vitest' },
          sequence: {},
          package: {
            version: '0.19.0',
            urls: { hooks: 'file:///c:/Users/david/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.345/wallabyf95907/runners/node/hooks.mjs' },
            paths: { root: 'C:\\dev\\ably-labs\\react-hooks\\node_modules\\vitest', dist: 'C:\\dev\\ably-labs\\react-hooks\\node_modules\\vitest\\dist' }
          }
        }
      }
    },
    testFramework: { version: 'vitest@0.14.0', configurator: 'vitest@0.14.0', reporter: 'vitest@0.14.0', starter: 'vitest@0.14.0', autoDetected: true },
    preserveComments: false,
    extractComments: true,
    files: [
      { pattern: '**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', ignore: true, trigger: true, load: true },
      { pattern: '**/node_modules/**', ignore: true, trigger: true, load: true },
      { pattern: '**/dist/**', ignore: true, trigger: true, load: true },
      { pattern: '**/cypress/**', ignore: true, trigger: true, load: true },
      { pattern: '**/.{idea,git,cache,output,temp}/**', ignore: true, trigger: true, load: true },
      { pattern: '**/*.*', ignore: false, trigger: true, load: true, order: 1 }
    ],
    tests: [
      { pattern: '**/node_modules/**', ignore: true, trigger: true, load: true, test: true },
      { pattern: '**/dist/**', ignore: true, trigger: true, load: true, test: true },
      { pattern: '**/cypress/**', ignore: true, trigger: true, load: true, test: true },
      { pattern: '**/.{idea,git,cache,output,temp}/**', ignore: true, trigger: true, load: true, test: true },
      { pattern: '**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', ignore: false, trigger: true, load: true, test: true, order: 2 }
    ],
    workers: { initial: 1, regular: 1, recycle: false },
    filesWithNoCoverageCalculated: [],
    runAllTestsInAffectedTestFile: false,
    updateNoMoreThanOneSnapshotPerTestFileRun: false,
    compilers: {},
    logLimits: { inline: { depth: 5, elements: 5000 }, values: { default: { stringLength: 200 }, autoExpand: { elements: 5000, stringLength: 8192, depth: 10 } } },
    preprocessors: {},
    maxConsoleMessagesPerTest: 100,
    autoConsoleLog: true,
    delays: { run: 0, edit: 100, update: 0 },
    teardown: undefined,
    hints: {
      ignoreCoverage: '__REGEXP /ignore coverage|istanbul ignore/',
      ignoreCoverageForFile: '__REGEXP /ignore file coverage/',
      commentAutoLog: '?',
      testFileSelection: { include: '__REGEXP /file\\.only/', exclude: '__REGEXP /file\\.skip/' }
    },
    automaticTestFileSelection: true,
    runSelectedTestsOnly: false,
    mapConsoleMessagesStackTrace: false,
    extensions: {},
    env: {
      type: 'node',
      params: { runner: '--experimental-loader=file:///c:/Users/david/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.345/wallabyf95907/runners/node/hooks.mjs' },
      runner: 'C:\\Program Files\\nodejs\\node.exe',
      viewportSize: { width: 800, height: 600 },
      options: { width: 800, height: 600 },
      bundle: true
    },
    reportUnhandledPromises: true,
    slowTestThreshold: 75,
    lowCoverageThreshold: 80,
    loose: undefined,
    symlinkNodeModules: true,
    configCode: 'auto.detect#1187933729'
  },
  packageJSON: {
    dependencies: { ably: '^1.2.22' },
    devDependencies: { '@testing-library/react': '^13.3.0', '@vitejs/plugin-react': '^1.3.2', jsdom: '^20.0.0', react: '>=18.1.0', 'react-dom': '>=18.1.0', typescript: '>=4.4.4', vitest: '^0.19.0' }
  },
  fs: { numberOfFiles: 20 },
  debug: []
}
@NikGovorov
Copy link
Member

At the moment we don't support root setting, to get the repo working please delete the settings from vitest.config.ts file. We'll be implementing support of the setting today or tomorrow.

@davidwhitney
Copy link
Author

Perfect, that seemed to prevent the issue. Thanks for the fast feedback :)

@smcenlly
Copy link
Member

Wallaby core v1.0.1306 now supports nested project root from your vitest configuration file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants