wallabyjs / public

Repository for Wallaby.js questions and issues
http://wallabyjs.com
760 stars 45 forks source link

Vitest - ReferenceError: $_$wp is not defined #3247

Closed tomitrescak closed 1 year ago

tomitrescak commented 1 year ago

Issue description or question

When running vitest in automatic mode I get $_$wp is not defined. This oinly happens when I set: threads: false in my vitest.workspace.ts file

This is the full vitest.workspace.ts file

import tsconfigPaths from "vite-tsconfig-paths";
import { defineWorkspace } from "vitest/config";

export default defineWorkspace([
  // you can use a list of glob patterns to define your workspaces
  // Vitest expects a list of config files
  // or directories where there is a config file
  {
    plugins: [tsconfigPaths()],
    // threads: false,
    test: {
      threads: false, // <-- This is the culprit
      name: "Server",
      include: ["src/server/**/*.test.ts"],
      environment: "node",
    },
  },
  // {
  //   plugins: [tsconfigPaths()],
  //   test: {
  //     name: "Python Compiler",
  //     include: ["src/compilers/pyodide/**/*.test.ts"],
  //     // root: './shared_tests',
  //     environment: "node",
  //     globals: true,
  //     // setupFiles: ['./setup.node.ts'],
  //   },
  // },
]);

I have to use that flag as I'm using canvas package and that is the documented fix

Wallaby diagnostics report

{
  editorVersion: '1.80.1',
  pluginVersion: '1.0.364',
  editorType: 'VSCode',
  osVersion: 'darwin 22.5.0',
  nodeVersion: 'v18.2.0',
  coreVersion: '1.0.1446',
  checksum: 'ZTk4NjZhZWJhMmJiMDkxZDc4NDU3MzM4NmM5N2JiNDMsMTcwMDA5MjgwMDAwMCww',
  config: {
    diagnostics: {
      vitest: {
        file: {
          config: 'import tsconfigPaths from "vite-tsconfig-paths";\n' +
            '// import { defineConfig } from "vitest/config";\n' +
            '\n' +
            '// export default defineConfig({\n' +
            '//   // plugins: [react()],\n' +
            '//   plugins: [react(), tsconfigPaths()],\n' +
            '//   test: {\n' +
            '//     include: ["src/**/*.test.tsx"],\n' +
            '//     globals: true,\n' +
            '//     environment: "happy-dom",\n' +
            '//   },\n' +
            '// });\n' +
            '\n' +
            'import { defineWorkspace } from "vitest/config";\n' +
            '\n' +
            'export default defineWorkspace([\n' +
            '  // you can use a list of glob patterns to define your workspaces\n' +
            '  // Vitest expects a list of config files\n' +
            '  // or directories where there is a config file\n' +
            "  // 'packages/*',\n" +
            "  // 'tests/*/vitest.config.{e2e,unit}.ts',\n" +
            '  // you can even run the same tests,\n' +
            '  // but with different configs in the same "vitest" process\n' +
            '  // {\n' +
            '  //   plugins: [react(), tsconfigPaths()],\n' +
            '  //   test: {\n' +
            '  //     name: "UI",\n' +
            "  //     // root: './shared_tests',\n" +
            '  //     environment: "happy-dom",\n' +
            '  //     include: ["src/**/*.test.tsx"],\n' +
            '  //     globals: true,\n' +
            "  //     // setupFiles: ['./setup.happy-dom.ts'],\n" +
            '  //   },\n' +
            '  // },\n' +
            '  {\n' +
            '    plugins: [tsconfigPaths()],\n' +
            '    // threads: false,\n' +
            '    test: {\n' +
            '      threads: false,\n' +
            '      name: "Server",\n' +
            '      include: ["src/server/**/*.test.ts"],\n' +
            "      // root: './shared_tests',\n" +
            '      environment: "node",\n' +
            '      // setupFiles: ["src/compilers/java/lib/extendExpect.ts"],\n' +
            '    },\n' +
            '  },\n' +
            '  // {\n' +
            '  //   plugins: [tsconfigPaths()],\n' +
            '  //   test: {\n' +
            '  //     name: "Python Compiler",\n' +
            '  //     include: ["src/compilers/pyodide/**/*.test.ts"],\n' +
            "  //     // root: './shared_tests',\n" +
            '  //     environment: "node",\n' +
            '  //     globals: true,\n' +
            "  //     // setupFiles: ['./setup.node.ts'],\n" +
            '  //   },\n' +
            '  // },\n' +
            '  // {\n' +
            '  //   plugins: [tsconfigPaths()],\n' +
            '  //   test: {\n' +
            '  //     name: "Java Compiler",\n' +
            '  //     include: ["src/compilers/java/**/*.test.ts"],\n' +
            "  //     // root: './shared_tests',\n" +
            '  //     environment: "node",\n' +
            '  //     globals: true,\n' +
            '  //     setupFiles: ["src/compilers/java/lib/extendExpect.ts"],\n' +
            '  //   },\n' +
            '  // },\n' +
            ']);\n'
        },
        config: {
          allowOnly: true,
          watch: true,
          globals: false,
          environment: 'node',
          threads: true,
          clearMocks: false,
          restoreMocks: false,
          mockReset: false,
          include: [ '**/*.{test,spec}.?(c|m)[jt]s?(x)' ],
          exclude: [
            '**/node_modules/**',
            '**/dist/**',
            '**/cypress/**',
            '**/.{idea,git,cache,output,temp}/**',
            '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*'
          ],
          testTimeout: 5000,
          hookTimeout: 10000,
          teardownTimeout: 10000,
          isolate: true,
          watchExclude: [ '**/node_modules/**', '**/dist/**' ],
          forceRerunTriggers: [ '**/package.json/**', '**/{vitest,vite}.config.*/**' ],
          update: false,
          reporters: [ 'default' ],
          silent: false,
          hideSkippedTests: false,
          ui: false,
          uiBase: '/__vitest__/',
          open: true,
          css: { include: [], modules: { classNameStrategy: 'stable' } },
          coverage: {
            provider: 'v8',
            enabled: false,
            clean: true,
            cleanOnRerun: true,
            reportsDirectory: './coverage',
            exclude: [
              'coverage/**',
              'dist/**',
              'packages/*/test?(s)/**',
              '**/*.d.ts',
              'cypress/**',
              'test?(s)/**',
              'test?(-*).?(c|m)[jt]s?(x)',
              '**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)',
              '**/__tests__/**',
              '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
              '**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}'
            ],
            reportOnFailure: true,
            reporter: [ [ 'text', {} ], [ 'html', {} ], [ 'clover', {} ], [ 'json', {} ] ],
            extension: [
              '.js',  '.cjs',
              '.mjs', '.ts',
              '.mts', '.cts',
              '.tsx', '.jsx',
              '.vue', '.svelte'
            ]
          },
          fakeTimers: { loopLimit: 10000, shouldClearNativeTimers: true, toFake: [ 'setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date' ] },
          maxConcurrency: 5,
          dangerouslyIgnoreUnhandledErrors: false,
          typecheck: {
            checker: 'tsc',
            include: [ '**/*.{test,spec}-d.?(c|m)[jt]s?(x)' ],
            exclude: [
              '**/node_modules/**',
              '**/dist/**',
              '**/cypress/**',
              '**/.{idea,git,cache,output,temp}/**',
              '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*'
            ]
          },
          slowTestThreshold: 300,
          defines: {},
          root: '<homeDir>/Github/clara',
          mode: [],
          inspect: false,
          inspectBrk: false,
          singleThread: false,
          deps: { inline: [ {}, {}, {}, '@nuxt/test-utils' ], moduleDirectories: [ '/node_modules/' ], registerNodeLoader: false, cacheDir: 'node_modules/.vite' },
          snapshotOptions: { snapshotFormat: {}, updateSnapshot: 'new', snapshotEnvironment: null },
          setupFiles: [],
          cache: { dir: '<homeDir>/Github/clara/node_modules/.vitest' },
          sequence: { hooks: 'parallel' },
          environmentMatchGlobs: [],
          browser: { enabled: false, headless: false, slowHijackESM: true, api: { port: 63315 } },
          package: {
            version: '0.33.0',
            urls: { hooks: 'file://<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.364/wallaby5f1b4a/runners/node/hooks.mjs' },
            paths: {
              root: '<homeDir>/Github/clara/node_modules/.pnpm/vitest@0.33.0_5an2nnzhyqtpegdes3vuehkbui/node_modules/vitest',
              dist: '<homeDir>/Github/clara/node_modules/.pnpm/vitest@0.33.0_5an2nnzhyqtpegdes3vuehkbui/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}.?(c|m)[jt]s?(x)', ignore: true, trigger: true, load: true, file: true },
      { pattern: '**/node_modules/**', ignore: true, trigger: true, load: true, file: true, test: true },
      { pattern: '**/dist/**', ignore: true, trigger: true, load: true, file: true, test: true },
      { pattern: '**/cypress/**', ignore: true, trigger: true, load: true, file: true, test: true },
      { pattern: '**/.{idea,git,cache,output,temp}/**', ignore: true, trigger: true, load: true, file: true, test: true },
      { pattern: '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*', ignore: true, trigger: true, load: true, file: true, test: true },
      { pattern: '**/*.*', ignore: false, trigger: true, load: true, order: 1 }
    ],
    tests: [
      { pattern: '**/node_modules/**', ignore: true, trigger: true, load: true, test: true, file: false },
      { pattern: '**/dist/**', ignore: true, trigger: true, load: true, test: true, file: false },
      { pattern: '**/cypress/**', ignore: true, trigger: true, load: true, test: true, file: false },
      { pattern: '**/.{idea,git,cache,output,temp}/**', ignore: true, trigger: true, load: true, test: true, file: false },
      { pattern: '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*', ignore: true, trigger: true, load: true, test: true, file: false },
      { pattern: '**/*.{test,spec}.?(c|m)[jt]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 2 }
    ],
    workers: { initial: 1, regular: 1, recycle: false },
    captureConsoleLog: true,
    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|c8 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://<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.364/wallaby5f1b4a/runners/node/hooks.mjs' },
      runner: '/usr/local/bin/node',
      viewportSize: { width: 800, height: 600 },
      options: { width: 800, height: 600 },
      bundle: true
    },
    reportUnhandledPromises: true,
    slowTestThreshold: 75,
    lowCoverageThreshold: 80,
    runAllTestsWhenNoAffectedTests: true,
    symlinkNodeModules: undefined,
    configCode: 'auto.detect#2145583041'
  },
  packageJSON: {
    dependencies: {
      '@apollo/client': '^3.7.15',
      '@babel/core': '^7.22.5',
      '@babel/plugin-proposal-class-properties': '^7.18.6',
      '@babel/plugin-proposal-decorators': '^7.22.5',
      '@babel/preset-typescript': '^7.22.5',
      '@babel/register': '^7.22.5',
      '@babel/standalone': '^7.22.5',
      '@ckeditor/ckeditor5-build-classic': '^38.0.1',
      '@ckeditor/ckeditor5-build-decoupled-document': '^38.0.1',
      '@ckeditor/ckeditor5-react': '^6.0.0',
      '@emotion/cache': '^11.11.0',
      '@emotion/core': '^11.0.0',
      '@emotion/react': '^11.11.1',
      '@emotion/styled': '^11.11.0',
      '@graphql-tools/graphql-file-loader': '^8.0.0',
      '@graphql-tools/load': '^8.0.0',
      '@graphql-tools/merge': '^9.0.0',
      '@graphql-tools/schema': '^10.0.0',
      '@lezer/common': '^1.0.3',
      '@lezer/python': '^1.1.7',
      '@loadable/component': '^5.15.3',
      '@monaco-editor/react': '^4.5.1',
      '@svgdotjs/svg.js': '^3.1.2',
      '@typescript-eslint/eslint-plugin': '^5.60.0',
      antlr4ts: '0.5.0-alpha.4',
      'apollo-connector-mongodb': '^5.0.0',
      'apollo-link-batch-http': '^1.2.14',
      'apollo-link-schema': '^1.2.5',
      'apollo-server-micro': '^3.12.0',
      'aws-sdk': '^2.1394.0',
      bcryptjs: '^2.4.3',
      buzz: '^1.2.1',
      canvas: '^2.11.2',
      canvg: '^4.0.1',
      'ckeditor5-custom-build': 'file:scripts/ckeditor5',
      classnames: '^2.3.2',
      cookies: '^0.8.0',
      cors: '^2.8.5',
      cypress: '^12.14.0',
      'date-fns': '^2.30.0',
      'diff-view': '^1.0.12',
      eslint: '^8.43.0',
      'eslint-config-next': '^13.4.4',
      forever: '^4.0.3',
      'framer-motion': '^10.12.16',
      glob: '^10.2.7',
      graphql: '^16.6.0',
      'highlight.js': '^11.8.0',
      'java-ast': '^0.3.0',
      'js-beautify': '^1.14.8',
      'js-cookie': '^3.0.5',
      jsdom: '^22.1.0',
      jszip: '^3.10.1',
      'jwt-decode': '^3.1.2',
      keyboardjs: '^2.7.0',
      lodash: '^4.17.21',
      'loop-protect': 'github:tomitrescak/loop-protect',
      'lru-cache': '^9.1.2',
      marked: '^5.0.5',
      'meteor-random': '^0.0.3',
      'meteor-sha256': '^1.0.1',
      micro: '^10.0.1',
      'micro-cors': '^0.1.1',
      mobx: '^6.9.0',
      'mobx-react': '^7.6.0',
      'monaco-editor': '^0.39.0',
      mongodb: '5.6.0',
      next: '13.4.4',
      'next-auth': '^4.22.1',
      'next-page-transitions': '1.0.0-beta.2',
      'next-themes': '^0.2.1',
      'node-fetch': '^3.3.1',
      nodemailer: '^6.9.3',
      prismjs: '^1.29.0',
      pyodide: '0.23.2',
      'python-ast': '^0.1.0',
      react: '^18.2.0',
      'react-alert': '^7.0.3',
      'react-alert-template-basic': '^1.0.2',
      'react-beautiful-dnd': '^13.1.1',
      'react-circular-progressbar': '^2.1.0',
      'react-color': '^2.19.3',
      'react-datepicker': '^4.12.0',
      'react-dom': '^18.2.0',
      'react-helmet': '^6.1.0',
      'react-object-inspector': '^0.2.1',
      'react-s3-uploader': '^5.0.0',
      'react-simple-code-editor': '^0.13.1',
      'react-split-pane': '^0.1.92',
      'react-transition-group': '^4.4.5',
      'react-virtualized': '^9.22.5',
      sass: '^1.63.2',
      'semantic-ui-css': '^2.5.0',
      'semantic-ui-react': '3.0.0-beta.0',
      'semantic-ui-react-numberinput': '^1.5.1',
      sinon: '^15.1.0',
      svg64: '^2.0.0',
      svgdom: '^0.1.14',
      sweetalert2: '^11.7.11',
      'ts-node': '^10.9.1',
      'tsconfig-paths': '^4.2.0',
      tslib: '^2.5.3',
      vega: '^5.25.0',
      'vite-tsconfig-paths': '^4.2.0',
      xmldom: '^0.6.0'
    },
    devDependencies: {
      '@graphql-codegen/cli': '^4.0.1',
      '@graphql-codegen/introspection': '^4.0.0',
      '@graphql-codegen/near-operation-file-preset': '^2.5.0',
      '@graphql-codegen/typescript': '^4.0.0',
      '@graphql-codegen/typescript-operations': '^4.0.0',
      '@graphql-codegen/typescript-react-apollo': '^3.3.7',
      '@graphql-codegen/typescript-resolvers': '^4.0.0',
      '@testing-library/cypress': '^9.0.0',
      '@testing-library/jest-dom': '^5.16.5',
      '@testing-library/react': '^14.0.0',
      '@types/babel__standalone': '^7.1.4',
      '@types/bcryptjs': '^2.4.2',
      '@types/classnames': '^2.3.1',
      '@types/js-cookie': '^3.0.3',
      '@types/jsdom': '^21.1.1',
      '@types/lodash': '^4.14.195',
      '@types/lru-cache': '^7.10.10',
      '@types/marked': '^5.0.0',
      '@types/node': '^20.2.5',
      '@types/nodemailer': '^6.4.8',
      '@types/react': '^18.2.9',
      '@types/react-alert': '^7.0.2',
      '@types/react-datepicker': '^4.11.2',
      '@types/react-dom': '^18.2.4',
      '@types/react-helmet': '^6.1.6',
      '@types/react-transition-group': '^4.4.6',
      '@types/react-virtualized': '^9.21.22',
      '@types/sinon': '^10.0.15',
      '@vitejs/plugin-react': '^4.0.3',
      'cypress-mochawesome-reporter': '^3.5.0',
      'happy-dom': '^10.5.2',
      'i18n-tag-schema': '^2.5.0',
      jsonwebtoken: '^9.0.0',
      'mongodb-memory-server': '^8.12.2',
      prettier: '^2.8.8',
      sinon: '^9.2.0',
      'start-server-and-test': '^2.0.0',
      typescript: '^5.1.3',
      vitest: '^0.33.0'
    }
  },
  fs: { numberOfFiles: 1715 },
  debug: []
}
smcenlly commented 1 year ago

Thanks for reporting the issue. This used to work in Wallaby but we just discovered it broke in vitest v0.0.29+ with some changes they made to how threads are executed.

We're investigating supporting the new threads: false execution model.

smcenlly commented 1 year ago

We've added experimental support for running vitest with threads: false in Wallaby core v1.0.1448.

Could you please update to the latest version? It should work for you.

If you have any further problems, please let us know.