wallabyjs / public

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

Jest Autoconfiguration: [Error] SyntaxError: Cannot use import statement outside a module #2687

Closed jljorgenson18 closed 3 years ago

jljorgenson18 commented 3 years ago

Issue description or question

(it's me again, but this time it's a different project so I can share everything)

I'm seeing an odd error related to module processing that I only see in Wallaby when running tests but not when I run jest manually. Even stranger, the issue only started occurring when I moved a test file out of the "tests/native/specs" directory and into the source code under a __tests__ dir. If I move the file back to the test/native directory, the problem goes away πŸ€·πŸ»β€β™‚οΈ

[Error] Runtime error: Jest encountered an unexpected token 
[Error] This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript. 
[Error] By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules". 
[Error] Here's what you can do: 
[Error]  β€’ If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it. 
[Error]  β€’ To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config. 
[Error]  β€’ If you need a custom transformation specify a "transform" option in your config. 
[Error]  β€’ If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option. 
[Error] You'll find more details and examples of these config options in the docs: 
[Error] https://jestjs.io/docs/en/configuration.html 
[Error] Details: 
[Error] ./node_modules/react-native/index.js:13 
[Error] import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo'; 
[Error] ^^^^^^ 
[Error] SyntaxError: Cannot use import statement outside a module 
[Error]     at new Script (vm.js:88:7) 
[Error]     at Runtime.createScriptFromCode (./node_modules/jest-runtime/build/index.js:1350:14) 
[Error]     at Runtime._execModule (./node_modules/jest-runtime/build/index.js:1245:25) 
[Error]     at Runtime._loadModule (./node_modules/jest-runtime/build/index.js:898:12) 
[Error]     at Runtime.requireModule (./node_modules/jest-runtime/build/index.js:746:10) 
[Error]     at Runtime.requireModuleOrMock (./node_modules/jest-runtime/build/index.js:919:21) 
[Error]     at Object.<anonymous> (./node_modules/@react-navigation/native/lib/commonjs/useBackButton.tsx:2:1) 
[Error]     at Runtime._execModule (./node_modules/jest-runtime/build/index.js:1299:24) 
[Error]     at Runtime._loadModule (./node_modules/jest-runtime/build/index.js:898:12) 
[Error]     at Runtime.requireModule (./node_modules/jest-runtime/build/index.js:746:10) 
[Error]     at Runtime.requireModuleOrMock (./node_modules/jest-runtime/build/index.js:919:21) 
[Error]     at Object.<anonymous> (./node_modules/@react-navigation/native/lib/commonjs/NavigationContainer.tsx:13:1) 
[Error]     at Runtime._execModule (./node_modules/jest-runtime/build/index.js:1299:24) 
[Error]     at Runtime._loadModule (./node_modules/jest-runtime/build/index.js:898:12) 
[Error]     at Runtime.requireModule (./node_modules/jest-runtime/build/index.js:746:10) 
[Error]     at Runtime.requireModuleOrMock (./node_modules/jest-runtime/build/index.js:919:21) 
[Error]     at Object.<anonymous> (./node_modules/@react-navigation/native/lib/commonjs/index.tsx:3:1) 
[Error]     at Runtime._execModule (./node_modules/jest-runtime/build/index.js:1299:24) 
[Error]     at Runtime._loadModule (./node_modules/jest-runtime/build/index.js:898:12) 
[Error]     at Runtime.requireModule (./node_modules/jest-runtime/build/index.js:746:10) 
[Error]     at Runtime.requireModuleOrMock (./node_modules/jest-runtime/build/index.js:919:21) 
[Error]     at Object.<anonymous> (./src/native/components/App.tsx:5:35) 
[Error]     at Runtime._execModule (./node_modules/jest-runtime/build/index.js:1299:24) 
[Error]     at Runtime._loadModule (./node_modules/jest-runtime/build/index.js:898:12) 
[Error]     at Runtime.requireModule (./node_modules/jest-runtime/build/index.js:746:10) 
[Error]     at Runtime.requireModuleOrMock (./node_modules/jest-runtime/build/index.js:919:21) 
[Error]     at Object.<anonymous> (./src/native/components/__tests__/App.spec.tsx:5:55) 
[Error]     at Runtime._execModule (./node_modules/jest-runtime/build/index.js:1299:24) 
[Error]     at Runtime._loadModule (./node_modules/jest-runtime/build/index.js:898:12) 
[Error]     at Runtime.requireModule (./node_modules/jest-runtime/build/index.js:746:10) 
[Error]     at jasmine2 (./node_modules/jest-jasmine2/build/index.js:230:13) 
[Error]     at runTestInternal (./node_modules/jest-runner/build/runTest.js:380:22) 
[Error]     at runTest (./node_modules/jest-runner/build/runTest.js:472:34) 

And here it is running just fine when I run jest by itself

> jest

 PASS  tests/native/specs/SanityCheck.ts
 PASS  tests/web/specs/SanityCheck.ts
 PASS  tests/common/specs/SanityCheck.ts
 PASS  src/web/components/pages/Dashboards/Widget/SingleNumber/__tests__/View.spec.tsx
 PASS  src/web/components/__tests__/App.spec.tsx
 PASS  src/native/components/__tests__/App.spec.tsx

Test Suites: 6 passed, 6 total
Tests:       7 passed, 7 total
Snapshots:   0 total
Time:        4.983s
Ran all test suites in 3 projects.

It seems like there is something subtly wrong with the Jest Wallaby autoconfiguration but I'm not sure what it is.

Wallaby diagnostics report

{
  editorVersion: '1.55.1',
  pluginVersion: '1.0.285',
  editorType: 'VSCode',
  osVersion: 'linux 5.11.0-7612-generic',
  nodeVersion: 'v12.18.2',
  coreVersion: '1.0.1061',
  checksum: 'ZDJlYzFiNTE4YzgwMTNiMGY3MWJjNDRjNDdlNWQwYjEsMTY0NDg4MzIwMDAwMCww',
  config: {
    diagnostics: {
      jest: {
        config: {
          configs: [
            {
              automock: false,
              cache: true,
              cacheDirectory: '/tmp/jest_rs',
              clearMocks: true,
              coveragePathIgnorePatterns: [ '/node_modules/' ],
              cwd: '<homeDir>/projects/daydash-ui',
              dependencyExtractor: undefined,
              detectLeaks: undefined,
              detectOpenHandles: undefined,
              displayName: undefined,
              errorOnDeprecated: false,
              extraGlobals: [],
              filter: undefined,
              forceCoverageMatch: [],
              globalSetup: undefined,
              globalTeardown: undefined,
              globals: {},
              haste: { computeSha1: false, throwOnModuleCollision: false },
              injectGlobals: true,
              moduleDirectories: [ 'node_modules' ],
              moduleFileExtensions: [ 'js', 'json', 'jsx', 'ts', 'tsx', 'node' ],
              moduleLoader: undefined,
              moduleNameMapper: [],
              modulePathIgnorePatterns: [],
              modulePaths: undefined,
              name: 'b167ac48ef383684ee46565cf8207c00',
              prettierPath: 'prettier',
              resetMocks: false,
              resetModules: false,
              resolver: undefined,
              restoreMocks: false,
              rootDir: '<homeDir>/projects/daydash-ui/tests/common',
              roots: [ '<homeDir>/projects/daydash-ui/tests/common', '<homeDir>/projects/daydash-ui' ],
              runner: 'jest-runner',
              setupFiles: [],
              setupFilesAfterEnv: [ '<homeDir>/projects/daydash-ui/tests/common/setup.ts' ],
              skipFilter: false,
              skipNodeResolution: undefined,
              slowTestThreshold: 5,
              snapshotResolver: undefined,
              snapshotSerializers: [],
              testEnvironment: '<homeDir>/projects/daydash-ui/node_modules/jest-environment-jsdom/build/index.js',
              testEnvironmentOptions: {},
              testLocationInResults: false,
              testMatch: [ '<homeDir>/projects/daydash-ui/tests/common/specs/**/*.[tj]s?(x)', '**/src/common/**/__tests__/**/*.spec.[jt]s?(x)' ],
              testPathIgnorePatterns: [ '/node_modules/' ],
              testRegex: [],
              testRunner: '<homeDir>/projects/daydash-ui/node_modules/jest-jasmine2/build/index.js',
              testURL: 'http://localhost',
              timers: 'real',
              transform: [ [ '^.+\\.[jt]sx?$', '<homeDir>/projects/daydash-ui/node_modules/babel-jest/build/index.js', {} ] ],
              transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ],
              unmockedModulePathPatterns: undefined,
              watchPathIgnorePatterns: []
            },
            {
              automock: false,
              cache: true,
              cacheDirectory: '/tmp/jest_rs',
              clearMocks: true,
              coveragePathIgnorePatterns: [ '/node_modules/' ],
              cwd: '<homeDir>/projects/daydash-ui',
              dependencyExtractor: undefined,
              detectLeaks: undefined,
              detectOpenHandles: undefined,
              displayName: undefined,
              errorOnDeprecated: false,
              extraGlobals: [],
              filter: undefined,
              forceCoverageMatch: [],
              globalSetup: undefined,
              globalTeardown: undefined,
              globals: {},
              haste: { defaultPlatform: 'ios', platforms: [ 'android', 'ios', 'native' ] },
              injectGlobals: true,
              moduleDirectories: [ 'node_modules' ],
              moduleFileExtensions: [ 'js', 'json', 'jsx', 'ts', 'tsx', 'node' ],
              moduleLoader: undefined,
              moduleNameMapper: [],
              modulePathIgnorePatterns: [],
              modulePaths: undefined,
              name: '22e3e1bf605d6265c0f849458d02aee4',
              prettierPath: 'prettier',
              resetMocks: false,
              resetModules: false,
              resolver: undefined,
              restoreMocks: false,
              rootDir: '<homeDir>/projects/daydash-ui/tests/native',
              roots: [ '<homeDir>/projects/daydash-ui/tests/native', '<homeDir>/projects/daydash-ui' ],
              runner: 'jest-runner',
              setupFiles: [
                '<homeDir>/projects/daydash-ui/node_modules/react-native/jest/setup.js',
                '<homeDir>/projects/daydash-ui/node_modules/jest-expo/src/preset/setup.js',
                '<homeDir>/projects/daydash-ui/node_modules/react-native-gesture-handler/jestSetup.js'
              ],
              setupFilesAfterEnv: [ '<homeDir>/projects/daydash-ui/tests/native/setup.ts' ],
              skipFilter: false,
              skipNodeResolution: undefined,
              slowTestThreshold: 5,
              snapshotResolver: undefined,
              snapshotSerializers: [],
              testEnvironment: '<homeDir>/projects/daydash-ui/node_modules/jest-environment-node/build/index.js',
              testEnvironmentOptions: {},
              testLocationInResults: false,
              testMatch: [ '<homeDir>/projects/daydash-ui/tests/native/specs/**/*.[tj]s?(x)', '**/src/native/**/__tests__/**/*.spec.[jt]s?(x)' ],
              testPathIgnorePatterns: [ '/node_modules/' ],
              testRegex: [],
              testRunner: '<homeDir>/projects/daydash-ui/node_modules/jest-jasmine2/build/index.js',
              testURL: 'http://localhost',
              timers: 'real',
              transform: [
                [ '^.+\\.[jt]sx?$', '<homeDir>/projects/daydash-ui/node_modules/babel-jest/build/index.js', { envName: 'test-expo' } ],
                [ '^.+\\.(js|ts|tsx)$', '<homeDir>/projects/daydash-ui/node_modules/babel-jest/build/index.js', {} ],
                [
                  '^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp|ttf|otf|m4v|mov|mp4|mpeg|mpg|webm|aac|aiff|caf|m4a|mp3|wav|html|pdf|obj)$',
                  '<homeDir>/projects/daydash-ui/node_modules/jest-expo/src/preset/assetFileTransformer.js',
                  {}
                ]
              ],
              transformIgnorePatterns: [
                'node_modules/(?!(jest-)?react-native|@react-native-community|@react-navigation|native-base|@expo(nent)?/.*|expo-.*/.*|@unimodules|@codler/react-native-keyboard-aware-scroll-view|@react-native-picker|victory-.*/.*/)'
              ],
              unmockedModulePathPatterns: undefined,
              watchPathIgnorePatterns: []
            },
            {
              automock: false,
              cache: true,
              cacheDirectory: '/tmp/jest_rs',
              clearMocks: true,
              coveragePathIgnorePatterns: [ '/node_modules/' ],
              cwd: '<homeDir>/projects/daydash-ui',
              dependencyExtractor: undefined,
              detectLeaks: undefined,
              detectOpenHandles: undefined,
              displayName: undefined,
              errorOnDeprecated: false,
              extraGlobals: [],
              filter: undefined,
              forceCoverageMatch: [],
              globalSetup: undefined,
              globalTeardown: undefined,
              globals: {},
              haste: { computeSha1: false, throwOnModuleCollision: false },
              injectGlobals: true,
              moduleDirectories: [ 'node_modules' ],
              moduleFileExtensions: [ 'js', 'json', 'jsx', 'ts', 'tsx', 'node' ],
              moduleLoader: undefined,
              moduleNameMapper: [
                [ '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$', '<homeDir>/projects/daydash-ui/tests/web/mocks/fileMock.ts' ],
                [ '\\.(css|scss)$', '<homeDir>/projects/daydash-ui/tests/web/mocks/styleMock.ts' ]
              ],
              modulePathIgnorePatterns: [],
              modulePaths: undefined,
              name: 'b720c86a66581b8aacbbeaa008a2a1dc',
              prettierPath: 'prettier',
              resetMocks: false,
              resetModules: false,
              resolver: undefined,
              restoreMocks: false,
              rootDir: '<homeDir>/projects/daydash-ui/tests/web',
              roots: [ '<homeDir>/projects/daydash-ui/tests/web', '<homeDir>/projects/daydash-ui' ],
              runner: 'jest-runner',
              setupFiles: [],
              setupFilesAfterEnv: [ '<homeDir>/projects/daydash-ui/tests/web/setup.ts' ],
              skipFilter: false,
              skipNodeResolution: undefined,
              slowTestThreshold: 5,
              snapshotResolver: undefined,
              snapshotSerializers: [],
              testEnvironment: '<homeDir>/projects/daydash-ui/node_modules/jest-environment-jsdom/build/index.js',
              testEnvironmentOptions: {},
              testLocationInResults: false,
              testMatch: [ '<homeDir>/projects/daydash-ui/tests/web/specs/**/*.[tj]s?(x)', '**/src/web/**/__tests__/**/*.spec.[jt]s?(x)' ],
              testPathIgnorePatterns: [ '/node_modules/' ],
              testRegex: [],
              testRunner: '<homeDir>/projects/daydash-ui/node_modules/jest-jasmine2/build/index.js',
              testURL: 'http://localhost',
              timers: 'real',
              transform: [
                [ '^.+\\.worker\\.[jt]s$', '<homeDir>/projects/daydash-ui/tests/web/mocks/workerize-jest.js', {} ],
                [ '^.+\\.[jt]sx?$', '<homeDir>/projects/daydash-ui/node_modules/babel-jest/build/index.js', {} ]
              ],
              transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ],
              unmockedModulePathPatterns: undefined,
              watchPathIgnorePatterns: []
            }
          ],
          globalConfig: {
            bail: 0,
            changedFilesWithAncestor: false,
            changedSince: undefined,
            collectCoverage: false,
            collectCoverageFrom: [],
            collectCoverageOnlyFrom: undefined,
            coverageDirectory: '<homeDir>/projects/daydash-ui/coverage',
            coverageProvider: 'babel',
            coverageReporters: [ 'json', 'text', 'lcov', 'clover' ],
            coverageThreshold: undefined,
            detectLeaks: undefined,
            detectOpenHandles: undefined,
            enabledTestsMap: undefined,
            errorOnDeprecated: false,
            expand: false,
            filter: undefined,
            findRelatedTests: false,
            forceExit: false,
            globalSetup: undefined,
            globalTeardown: undefined,
            json: false,
            lastCommit: false,
            listTests: undefined,
            logHeapUsage: false,
            maxConcurrency: 5,
            maxWorkers: 7,
            noSCM: undefined,
            noStackTrace: false,
            nonFlagArgs: undefined,
            notify: false,
            notifyMode: 'failure-change',
            onlyChanged: false,
            onlyFailures: false,
            outputFile: undefined,
            passWithNoTests: undefined,
            projects: [ 'tests/common/jest.config.js', 'tests/native/jest.config.js', 'tests/web/jest.config.js' ],
            replname: undefined,
            reporters: undefined,
            rootDir: '<homeDir>/projects/daydash-ui',
            runTestsByPath: false,
            silent: undefined,
            skipFilter: false,
            testFailureExitCode: 1,
            testNamePattern: undefined,
            testPathPattern: '',
            testResultsProcessor: undefined,
            testSequencer: '<homeDir>/projects/daydash-ui/node_modules/@jest/test-sequencer/build/index.js',
            testTimeout: undefined,
            updateSnapshot: 'new',
            useStderr: false,
            verbose: undefined,
            watch: false,
            watchAll: false,
            watchPlugins: undefined,
            watchman: true
          },
          hasDeprecationWarnings: false,
          wallaby: {
            roots: [ 'tests/common', 'tests/native', 'tests/web' ],
            watchPathIgnorePatterns: [ '/node_modules/', '\\./dist/|\\./build/|\\./coverage/|/\\..+/|android/|ios/' ],
            testPathIgnorePatterns: [ '/node_modules/', '\\./dist/|\\./build/|\\./coverage/|/\\..+/|android/|ios/' ],
            testMatch: [
              'tests/common/specs/**/*.[tj]s?(x)',
              '**/src/common/**/__tests__/**/*.spec.[jt]s?(x)',
              'tests/native/specs/**/*.[tj]s?(x)',
              '**/src/native/**/__tests__/**/*.spec.[jt]s?(x)',
              'tests/web/specs/**/*.[tj]s?(x)',
              '**/src/web/**/__tests__/**/*.spec.[jt]s?(x)'
            ],
            testRegex: []
          }
        }
      }
    },
    testFramework: { version: 'jest@24.8.0', configurator: 'jest@24.8.0', reporter: 'jest@24.8.0', starter: 'jest@24.8.0', autoDetected: true },
    filesWithCoverageCalculated: [],
    filesWithNoCoverageCalculated: [],
    globalSetup: false,
    micromatch: true,
    files: [
      { pattern: '/node_modules/', regexp: /\/node_modules\//, ignore: true, trigger: true, load: true },
      {
        pattern: '\\./dist/|\\./build/|\\./coverage/|/\\..+/|android/|ios/',
        regexp: /\.\/dist\/|\.\/build\/|\.\/coverage\/|\/\..+\/|android\/|ios\//,
        ignore: true,
        trigger: true,
        load: true
      },
      { pattern: '**/**', ignore: false, trigger: true, load: true, order: 1 },
      { pattern: 'tests/common/**', ignore: false, trigger: true, load: true, order: 2 },
      { pattern: 'tests/native/**', ignore: false, trigger: true, load: true, order: 3 },
      { pattern: 'tests/web/**', ignore: false, trigger: true, load: true, order: 4 },
      { pattern: 'tests/common/specs/**/*.[tj]s?(x)', ignore: true, trigger: true, load: true },
      { pattern: '**/src/common/**/__tests__/**/*.spec.[jt]s?(x)', ignore: true, trigger: true, load: true },
      { pattern: 'tests/native/specs/**/*.[tj]s?(x)', ignore: true, trigger: true, load: true },
      { pattern: '**/src/native/**/__tests__/**/*.spec.[jt]s?(x)', ignore: true, trigger: true, load: true },
      { pattern: 'tests/web/specs/**/*.[tj]s?(x)', ignore: true, trigger: true, load: true },
      { pattern: '**/src/web/**/__tests__/**/*.spec.[jt]s?(x)', ignore: true, trigger: true, load: true }
    ],
    tests: [
      { pattern: '/node_modules/', regexp: /\/node_modules\//, ignore: true, trigger: true, load: true, test: true },
      {
        pattern: '\\./dist/|\\./build/|\\./coverage/|/\\..+/|android/|ios/',
        regexp: /\.\/dist\/|\.\/build\/|\.\/coverage\/|\/\..+\/|android\/|ios\//,
        ignore: true,
        trigger: true,
        load: true,
        test: true
      },
      { pattern: 'tests/common/specs/**/*.[tj]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 5 },
      { pattern: '**/src/common/**/__tests__/**/*.spec.[jt]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 6 },
      { pattern: 'tests/native/specs/**/*.[tj]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 7 },
      { pattern: '**/src/native/**/__tests__/**/*.spec.[jt]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 8 },
      { pattern: 'tests/web/specs/**/*.[tj]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 9 },
      { pattern: '**/src/web/**/__tests__/**/*.spec.[jt]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 10 }
    ],
    runAllTestsInAffectedTestFile: false,
    updateNoMoreThanOneSnapshotPerTestFileRun: false,
    addModifiedTestFileToExclusiveTestRun: true,
    compilers: {},
    preprocessors: {},
    maxConsoleMessagesPerTest: 100,
    autoConsoleLog: true,
    delays: { run: 0, edit: 100, update: 0 },
    workers: { initial: 0, regular: 0, recycle: false },
    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: '/usr/bin/node', viewportSize: { width: 800, height: 600 }, options: { width: 800, height: 600 }, bundle: true },
    reportUnhandledPromises: true,
    slowTestThreshold: 75,
    lowCoverageThreshold: 80,
    loose: true,
    configCode: 'auto.detect#689727448'
  },
  packageJSON: {
    dependencies: {
      '@expo-google-fonts/jura': '^0.1.0',
      '@expo/vector-icons': '^12.0.4',
      '@react-native-community/async-storage': '^1.12.1',
      '@react-native-community/masked-view': '0.1.10',
      '@react-navigation/bottom-tabs': '^5.11.9',
      '@react-navigation/drawer': '^5.12.5',
      '@react-navigation/native': '^5.9.4',
      '@react-navigation/stack': '^5.14.4',
      axios: '^0.21.1',
      'convert-units': '^2.3.4',
      'core-js': '^3.10.1',
      'date-fns': '^2.20.3',
      expo: '^40.0.1',
      'expo-app-loading': '^1.0.1',
      'expo-asset': '^8.2.2',
      'expo-blur': '~8.2.2',
      'expo-checkbox': '^1.0.2',
      'expo-constants': '~9.3.0',
      'expo-font': '~8.4.0',
      'expo-linking': '^2.1.1',
      'expo-splash-screen': '~0.8.0',
      'expo-status-bar': '~1.0.3',
      'expo-updates': '~0.4.1',
      'expo-web-browser': '~8.6.0',
      flat: '^5.0.2',
      formik: '^2.2.6',
      grommet: '^2.17.1',
      'grommet-icons': '^4.5.0',
      'grommet-styles': '^0.2.0',
      lodash: '^4.17.21',
      'markdown-it-checkbox': '^1.1.0',
      'native-base': '^2.15.2',
      polished: '^4.1.1',
      qs: '^6.10.1',
      react: '^17.0.2',
      'react-beautiful-dnd': '^13.1.0',
      'react-dom': '^17.0.2',
      'react-native': 'https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz',
      'react-native-draggable-flatlist': '^2.6.0',
      'react-native-expo-image-cache': '^4.1.0',
      'react-native-gesture-handler': '^1.10.3',
      'react-native-get-random-values': '^1.7.0',
      'react-native-markdown-display': '^7.0.0-alpha.2',
      'react-native-popup-menu': '^0.15.10',
      'react-native-reanimated': '^1.13.2',
      'react-native-safe-area-context': '^3.2.0',
      'react-native-screens': '^2.15.2',
      'react-native-svg': '^12.1.0',
      'react-native-web': '^0.14.10',
      'react-native-webview': '^11.4.0',
      'react-query': '^3.13.7',
      'react-query-devtools': '^2.6.3',
      'react-router-dom': '^5.2.0',
      'react-sidebar': '^3.0.2',
      'react-spring': '^8.0.27',
      'regenerator-runtime': '^0.13.7',
      reselect: '^4.0.0',
      'resize-observer-polyfill': '^1.5.1',
      'styled-components': '^5.2.3',
      'use-undo': '^1.0.3',
      uuid: '^8.3.2',
      victory: '^35.5.1',
      'victory-core': '^35.5.1',
      'victory-native': '^35.3.2',
      webfontloader: '^1.6.28',
      yup: '^0.32.9'
    },
    devDependencies: {
      '@babel/core': '^7.13.15',
      '@babel/plugin-proposal-class-properties': '^7.13.0',
      '@babel/preset-env': '^7.13.15',
      '@babel/preset-react': '^7.13.13',
      '@babel/preset-typescript': '^7.13.0',
      '@pmmmwh/react-refresh-webpack-plugin': '^0.4.3',
      '@testing-library/cypress': '^7.0.5',
      '@testing-library/react': '^11.2.6',
      '@testing-library/react-hooks': '^3.7.0',
      '@testing-library/react-native': '^7.2.0',
      '@types/convert-units': '^2.3.3',
      '@types/flat': '^5.0.1',
      '@types/gapi': '0.0.39',
      '@types/jest': '^26.0.22',
      '@types/little-loader': '^0.2.0',
      '@types/lodash': '^4.14.168',
      '@types/markdown-it': '^12.0.1',
      '@types/qs': '^6.9.6',
      '@types/react': '^17.0.3',
      '@types/react-beautiful-dnd': '^13.0.0',
      '@types/react-dom': '^17.0.3',
      '@types/react-loader-spinner': '^3.1.3',
      '@types/react-native': '^0.63.46',
      '@types/react-router-dom': '^5.1.7',
      '@types/react-sidebar': '^3.0.0',
      '@types/recharts': '^1.8.19',
      '@types/styled-components': '^5.1.9',
      '@types/styled-components-react-native': '^5.1.1',
      '@types/testing-library__cypress': '^5.0.8',
      '@types/uuid': '^8.3.0',
      '@types/webfontloader': '^1.6.32',
      '@types/webpack-env': '^1.16.0',
      '@types/yup': '^0.29.11',
      '@typescript-eslint/eslint-plugin': '^4.22.0',
      '@typescript-eslint/parser': '^4.22.0',
      'babel-jest': '^26.6.3',
      'babel-loader': '^8.2.2',
      'babel-plugin-lodash': '^3.3.4',
      'babel-plugin-module-resolver': '^4.1.0',
      'babel-plugin-styled-components': '^1.12.0',
      'case-sensitive-paths-webpack-plugin': '^2.4.0',
      'clean-webpack-plugin': '^3.0.0',
      concurrently: '^5.3.0',
      'cross-env': '^7.0.3',
      'css-loader': '^5.2.1',
      cypress: '^6.8.0',
      eslint: '^7.24.0',
      'eslint-config-prettier': '^6.15.0',
      'eslint-plugin-prettier': '^3.3.1',
      'eslint-plugin-react': '^7.23.2',
      'eslint-plugin-react-hooks': '^4.2.0',
      faker: '^5.5.3',
      'favicons-webpack-plugin': '^4.2.0',
      'file-loader': '^6.2.0',
      'html-webpack-plugin': '^4.5.1',
      husky: '^4.3.8',
      'imagemin-webpack-plugin': '^2.4.2',
      ip: '^1.1.5',
      jest: '^26.4.2',
      'jest-expo': '^41.0.0',
      msw: '^0.28.1',
      prettier: '^2.1.2',
      'react-refresh': '^0.9.0',
      'style-loader': '^1.3.0',
      typescript: '^4.2.4',
      'url-loader': '^4.0.0',
      webpack: '^4.44.2',
      'webpack-cli': '^3.3.11',
      'webpack-dev-server': '^3.11.2',
      'workerize-loader': '^1.3.0'
    }
  },
  fs: { numberOfFiles: 201 },
  debug: [
    '2021-04-15T16:48:09.957Z angular/cli config Angular CLI not found.\n',
    '2021-04-15T16:48:10.153Z jest/config Detected Jest.\n',
    '2021-04-15T16:48:10.154Z jest/config Configured Jest.\n',
    '2021-04-15T16:48:10.156Z project Wallaby Node version: v12.18.2\n',
    '2021-04-15T16:48:10.156Z project Wallaby config: <homeDir>/projects/daydash-ui/auto.detect\n',
    '2021-04-15T16:48:10.509Z project File cache: <homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.285/projects/a447e2bcbfd1b8c7\n',
    '2021-04-15T16:48:10.605Z uiService Listening port 51235\n',
    '2021-04-15T16:48:10.620Z project package.json file change detected, invalidating local cache\n',
    '2021-04-15T16:48:10.710Z workers Parallelism for initial run: 6, for regular run: 3\n',
    '2021-04-15T16:48:10.711Z workers Starting run worker instance #0\n',
    '2021-04-15T16:48:10.711Z workers Starting run worker instance #1\n',
    '2021-04-15T16:48:10.711Z workers Starting run worker instance #2\n',
    '2021-04-15T16:48:10.712Z workers Starting run worker instance #3\n',
    '2021-04-15T16:48:10.712Z workers Starting run worker instance #4\n',
    '2021-04-15T16:48:10.712Z workers Starting run worker instance #5\n',
    '2021-04-15T16:48:10.712Z workers Web server is listening at 42487\n',
    '2021-04-15T16:48:10.713Z project File cache requires some updates, waiting required files from IDE\n',
    '2021-04-15T16:48:10.836Z project Stopping process pool\n',
    '2021-04-15T16:48:10.840Z project Test run started; run priority: 3\n',
    '2021-04-15T16:48:10.843Z project Running all tests\n',
    '2021-04-15T16:48:10.853Z workers Starting test run, priority: 3\n',
    '2021-04-15T16:48:10.854Z workers Distributing tests between 6 workers\n',
    '2021-04-15T16:48:10.854Z workers Running tests in parallel\n',
    '2021-04-15T16:48:10.859Z nodeRunner Starting sandbox [worker #0, session #bh5v4]\n',
    '2021-04-15T16:48:10.859Z nodeRunner Starting sandbox [worker #1, session #z426t]\n',
    '2021-04-15T16:48:10.859Z nodeRunner Starting sandbox [worker #2, session #qocnl]\n',
    '2021-04-15T16:48:10.859Z nodeRunner Starting sandbox [worker #3, session #kliz2]\n',
    '2021-04-15T16:48:10.861Z nodeRunner Starting sandbox [worker #4, session #g787s]\n',
    '2021-04-15T16:48:10.861Z nodeRunner Starting sandbox [worker #5, session #xvou9]\n',
    '2021-04-15T16:48:10.861Z nodeRunner Preparing sandbox [worker #0, session #bh5v4]\n',
    '2021-04-15T16:48:10.861Z nodeRunner Preparing sandbox [worker #1, session #z426t]\n',
    '2021-04-15T16:48:10.862Z nodeRunner Preparing sandbox [worker #2, session #qocnl]\n',
    '2021-04-15T16:48:10.862Z nodeRunner Preparing sandbox [worker #3, session #kliz2]\n',
    '2021-04-15T16:48:10.862Z nodeRunner Preparing sandbox [worker #4, session #g787s]\n',
    '2021-04-15T16:48:10.862Z nodeRunner Preparing sandbox [worker #5, session #xvou9]\n',
    '2021-04-15T16:48:11.075Z workers Started run worker instance (delayed) #0\n',
    '2021-04-15T16:48:11.076Z nodeRunner Prepared sandbox [worker #0, session #bh5v4]\n',
    '2021-04-15T16:48:11.077Z workers [worker #0, session #bh5v4] Running tests in sandbox\n',
    '2021-04-15T16:48:11.089Z workers Started run worker instance (delayed) #1\n',
    '2021-04-15T16:48:11.089Z nodeRunner Prepared sandbox [worker #1, session #z426t]\n',
    '2021-04-15T16:48:11.090Z workers [worker #1, session #z426t] Running tests in sandbox\n',
    '2021-04-15T16:48:11.100Z workers Started run worker instance (delayed) #5\n',
    '2021-04-15T16:48:11.101Z nodeRunner Prepared sandbox [worker #5, session #xvou9]\n',
    '2021-04-15T16:48:11.101Z workers [worker #5, session #xvou9] Running tests in sandbox\n',
    '2021-04-15T16:48:11.108Z workers Started run worker instance (delayed) #2\n',
    '2021-04-15T16:48:11.108Z nodeRunner Prepared sandbox [worker #2, session #qocnl]\n',
    '2021-04-15T16:48:11.109Z workers [worker #2, session #qocnl] Running tests in sandbox\n',
    '2021-04-15T16:48:11.116Z workers Started run worker instance (delayed) #4\n',
    '2021-04-15T16:48:11.117Z nodeRunner Prepared sandbox [worker #4, session #g787s]\n',
    '2021-04-15T16:48:11.117Z workers [worker #4, session #g787s] Running tests in sandbox\n',
    '2021-04-15T16:48:11.197Z workers Started run worker instance (delayed) #3\n',
    '2021-04-15T16:48:11.198Z nodeRunner Prepared sandbox [worker #3, session #kliz2]\n',
    '2021-04-15T16:48:11.198Z workers [worker #3, session #kliz2] Running tests in sandbox\n',
    '2021-04-15T16:48:12.221Z uiService UI client connected\n',
    '2021-04-15T16:48:12.222Z uiService Outgoing message ui:handshake\n',
    '2021-04-15T16:48:12.227Z uiService Incoming message ui:tests:resultsRequested\n',
    '2021-04-15T16:48:12.229Z uiService Outgoing message ui:tests:allResultsUpdated\n',
    '2021-04-15T16:48:12.230Z uiService Incoming message ui:start\n',
    '2021-04-15T16:48:12.231Z uiService Outgoing message ui:summary\n',
    '2021-04-15T16:48:12.235Z uiService Outgoing message ui:files\n',
    '2021-04-15T16:48:18.103Z workers Scheduling Jest Test Run: 2021-04-15T16:48:13.957Z\n',
    '2021-04-15T16:48:18.117Z workers Scheduling Jest Test Run: 2021-04-15T16:48:13.957Z\n',
    '2021-04-15T16:48:18.117Z workers [bh5v4] Loaded unknown number of test(s)\n',
    '2021-04-15T16:48:18.119Z workers [bh5v4] Test executed: should be true\n',
    '2021-04-15T16:48:18.123Z workers [bh5v4] Run 1 test(s), skipped 0 test(s)\n',
    '2021-04-15T16:48:18.124Z workers [kliz2] Loaded unknown number of test(s)\n',
    '2021-04-15T16:48:18.124Z workers Jest Test Run Complete: 2021-04-15T16:48:18.099Z\n',
    '2021-04-15T16:48:18.124Z workers [kliz2] Test executed: should be true\n',
    '2021-04-15T16:48:18.126Z workers [bh5v4] Sandbox is responsive, closing it\n',
    '2021-04-15T16:48:18.131Z workers [kliz2] Run 1 test(s), skipped 0 test(s)\n',
    '2021-04-15T16:48:18.132Z workers Jest Test Run Complete: 2021-04-15T16:48:18.104Z\n',
    '2021-04-15T16:48:18.133Z workers [kliz2] Sandbox is responsive, closing it\n',
    '2021-04-15T16:48:18.274Z workers Scheduling Jest Test Run: 2021-04-15T16:48:13.936Z\n',
    '2021-04-15T16:48:18.276Z workers [z426t] Loaded unknown number of test(s)\n',
    '2021-04-15T16:48:18.276Z workers [z426t] Test executed: should be true\n',
    '2021-04-15T16:48:18.277Z workers [z426t] Run 1 test(s), skipped 0 test(s)\n',
    '2021-04-15T16:48:18.278Z workers Jest Test Run Complete: 2021-04-15T16:48:18.271Z\n',
    '2021-04-15T16:48:18.279Z workers [z426t] Sandbox is responsive, closing it\n',
    '2021-04-15T16:48:18.558Z workers Scheduling Jest Test Run: 2021-04-15T16:48:13.978Z\n',
    '2021-04-15T16:48:18.586Z workers Sandbox (active) [qocnl] error: Cannot use import statement outside a module\n',
    '2021-04-15T16:48:18.612Z workers [qocnl] Run 0 test(s), skipped 0 test(s)\n',
    '2021-04-15T16:48:18.613Z workers Jest Test Run Complete: 2021-04-15T16:48:18.554Z\n',
    '2021-04-15T16:48:18.615Z workers [qocnl] Sandbox is responsive, closing it\n',
    '2021-04-15T16:48:21.583Z workers Scheduling Jest Test Run: 2021-04-15T16:48:14.003Z\n',
    '2021-04-15T16:48:21.654Z workers [xvou9] Loaded unknown number of test(s)\n',
    '2021-04-15T16:48:21.655Z workers [xvou9] Test executed: should render\n',
    '2021-04-15T16:48:21.655Z workers [xvou9] Test executed: should handle the case where no aggregate data is available\n',
    '2021-04-15T16:48:21.658Z workers [xvou9] Run 2 test(s), skipped 0 test(s)\n',
    '2021-04-15T16:48:21.658Z workers Jest Test Run Complete: 2021-04-15T16:48:21.603Z\n',
    '2021-04-15T16:48:21.660Z workers [xvou9] Sandbox is responsive, closing it\n',
    '2021-04-15T16:48:24.518Z workers Scheduling Jest Test Run: 2021-04-15T16:48:13.942Z\n',
    '2021-04-15T16:48:24.625Z workers [g787s] Loaded unknown number of test(s)\n',
    '2021-04-15T16:48:24.625Z workers [g787s] Test executed: should render the App\n',
    '2021-04-15T16:48:24.632Z workers [g787s] Run 1 test(s), skipped 0 test(s)\n',
    '2021-04-15T16:48:24.633Z workers Jest Test Run Complete: 2021-04-15T16:48:24.516Z\n',
    '2021-04-15T16:48:24.634Z workers [g787s] Sandbox is responsive, closing it\n',
    '2021-04-15T16:48:24.634Z workers Merging parallel test run results\n',
    '2021-04-15T16:48:24.636Z project Test run finished\n',
    '2021-04-15T16:48:24.637Z project Processed console.log entries\n',
    '2021-04-15T16:48:24.637Z project Processed loading sequences\n',
    '2021-04-15T16:48:24.638Z project Processed executed tests\n',
    '2021-04-15T16:48:24.650Z project Processed code coverage\n',
    '2021-04-15T16:48:24.688Z project Test run result processed and sent to IDE\n',
    '2021-04-15T16:48:24.688Z uiService Outgoing message ui:summary\n',
    '2021-04-15T16:48:24.690Z uiService Outgoing message ui:tests:allResultsUpdated\n',
    '2021-04-15T16:48:24.692Z uiService Outgoing message ui:coverageChanged\n'
  ]
}
ArtemGovorov commented 3 years ago
 PASS  tests/native/specs/SanityCheck.ts
 PASS  tests/web/specs/SanityCheck.ts
 PASS  tests/common/specs/SanityCheck.ts
 PASS  src/web/components/pages/Dashboards/Widget/SingleNumber/__tests__/View.spec.tsx
 PASS  src/web/components/__tests__/App.spec.tsx
 PASS  src/native/components/__tests__/App.spec.tsx
jljorgenson18 commented 3 years ago

I don't have a root jest config, just this is in package.json

  "jest": {
    "projects": [
      "tests/common/jest.config.js",
      "tests/native/jest.config.js",
      "tests/web/jest.config.js"
    ]
  },

The test that fails is PASS src/native/components/__tests__/App.spec.tsx and all it fails at importing

import {
  NavigationContainer,
  Theme as NavTheme
} from '@react-navigation/native';

Inside of the root App component. Here are the three jest configs

Native

module.exports = {
  preset: 'jest-expo',
  clearMocks: true,
  testMatch: [
    '<rootDir>/specs/**/*.[tj]s?(x)',
    '**/src/native/**/__tests__/**/*.spec.[jt]s?(x)'
  ],
  roots: ['<rootDir>', '../../'],
  setupFiles: ['../../node_modules/react-native-gesture-handler/jestSetup.js'],
  setupFilesAfterEnv: ['<rootDir>/setup.ts'],
  moduleNameMapper: {},
  transform: {
    '^.+\\.[jt]sx?$': ['babel-jest', { envName: 'test-expo' }]
  },
  transformIgnorePatterns: [
    'node_modules/(?!(jest-)?react-native' +
      '|@react-native-community' +
      '|@react-navigation' +
      '|native-base' +
      '|@expo(nent)?/.*' +
      '|expo-.*/.*' +
      '|@unimodules' +
      '|@codler/react-native-keyboard-aware-scroll-view' +
      '|@react-native-picker' +
      '|victory-.*/.*' +
      '/)'
  ]
};

Common

module.exports = {
  clearMocks: true,
  testMatch: [
    '<rootDir>/specs/**/*.[tj]s?(x)',
    '**/src/common/**/__tests__/**/*.spec.[jt]s?(x)'
  ],
  roots: ['<rootDir>', '../../'],
  setupFilesAfterEnv: ['<rootDir>/setup.ts'],
  moduleNameMapper: {},
  transform: {
    '^.+\\.[jt]sx?$': 'babel-jest'
  }
};

Web

module.exports = {
  clearMocks: true,
  testMatch: [
    '<rootDir>/specs/**/*.[tj]s?(x)',
    '**/src/web/**/__tests__/**/*.spec.[jt]s?(x)'
  ],
  roots: ['<rootDir>', '../../'],
  setupFilesAfterEnv: ['<rootDir>/setup.ts'],
  moduleNameMapper: {
    '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
      '<rootDir>/mocks/fileMock.ts',
    '\\.(css|scss)$': '<rootDir>/mocks/styleMock.ts'
  },
  transform: {
    '^.+\\.worker\\.[jt]s$': '<rootDir>/mocks/workerize-jest.js',
    '^.+\\.[jt]sx?$': 'babel-jest'
  }
};
ArtemGovorov commented 3 years ago

Thanks, I'm trying to reproduce the issue by creating a sample project, but looks like I'm still missing some configs because running jest from command line is throwing some errors. Can you please share your Babel config and tsconfig.json?

jljorgenson18 commented 3 years ago

Here is the babel config

module.exports = api => {
  const env = process.env.NODE_ENV;
  const isNative = Boolean(process.env.EXPO_TARGET || api.env('test-expo'));
  const isTest = api.env('test') || api.env('test-expo');
  const isDev = !api.env('production');
  api.cache.using(() => env + '-' + isNative);
  const aliases = {
    src: './src',
    tests: './tests'
  };
  if (!isNative) {
    aliases['^react-native$'] = 'react-native-web';
  }
  const moduleResolverConfig = [
    'module-resolver',
    {
      alias: aliases
    }
  ];
  if (isNative) {
    return {
      presets: ['babel-preset-expo'],
      plugins: [moduleResolverConfig]
    };
  }
  return {
    presets: [
      '@babel/preset-typescript',
      [
        '@babel/preset-env',
        isTest
          ? {
              debug: false,
              useBuiltIns: 'usage',
              corejs: '3',
              targets: {
                node: 'current'
              }
            }
          : {
              modules: false,
              debug: false,
              useBuiltIns: 'usage',
              corejs: '3'
            }
      ],
      '@babel/preset-react'
    ],
    plugins: [
      moduleResolverConfig,
      '@babel/plugin-proposal-class-properties',
      '@babel/plugin-proposal-object-rest-spread',
      'lodash',
      isDev && !isNative && !isTest ? 'react-refresh/babel' : null,
      'babel-plugin-styled-components'
    ].filter(Boolean)
  };
};

I can give the tsconfigs but I don't think they could play a role here as they are only doing type checks and they are a bit complicated. All transpiling is done through babel

ArtemGovorov commented 3 years ago

Thanks, babel config was enough to reproduce.

Wallaby is using Jest API internally to resolve configs and it looks like the external API may be working slightly differently from the internal Jest config resolution.

The issue is that for some reason Jest seems to either resolve tests/native/jest.config.js config first or use its transformIgnorePatterns for the src/native/components/__tests__/* tests.

Either way, there's a simple solution to make it work, just change your package.json Jest config to have the tests/native/jest.config.js project to be the first in the list:

  "jest": {
    "projects": [
      "tests/native/jest.config.js",
      "tests/common/jest.config.js",
      "tests/web/jest.config.js"
    ]
  },

and everything should work in both Jest CLI and Wallaby Jest.

jljorgenson18 commented 3 years ago

So actually changing the order somehow screws up the web config which causes JSDom to not be loaded for the web specific tests

nfo]β€ˆ console.log: Jest:   ● should render the App
[Info]β€ˆ     The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/en/configuration#testenvironment-string.
[Info]β€ˆ     Consider using the "jsdom" test environment.
[Info]β€ˆ     ReferenceError: document is not defined
[Info]β€ˆ       at render (../../node_modules/@testing-library/react/dist/pure.js:81:5)

This brought me from 1/7 failing tests to 3/7 πŸ˜†

I guess if the external API is not doing the right stuff, there isn't a whole lot that can be done except filing a bug for Jest.

ArtemGovorov commented 3 years ago

So actually changing the order somehow screws up the web config which causes JSDom to not be loaded for the web specific tests

Hmm, interesting... Let me investigate it a bit more then.

ArtemGovorov commented 3 years ago

While we're further investigating the issue, here's a workaround that may help: add the same transformIgnorePatterns as in your tests/native Jest config to the 2 other Jest configs:

    transformIgnorePatterns: [
      'node_modules/(?!(jest-)?react-native' +
        '|@react-native-community' +
        '|@react-navigation' +
        '|native-base' +
        '|@expo(nent)?/.*' +
        '|expo-.*/.*' +
        '|@unimodules' +
        '|@codler/react-native-keyboard-aware-scroll-view' +
        '|@react-native-picker' +
        '|victory-.*/.*' +
        '/)'
    ]

Let us know if the workaround works for you.

jljorgenson18 commented 3 years ago

Adding the additional transformIgnorePatterns didn't seem to change anything. The issue seems to stem more from the presets being slightly off so maybe jest-expo isn't being applied somehow?

jljorgenson18 commented 3 years ago

I found the issue earlier today which might be related https://github.com/facebook/jest/issues/10111

maybe there was a recent Jest regression?

ArtemGovorov commented 3 years ago

We've been able to identify the root cause of the issue and fix it. Please force update to the latest Wallaby core v1.0.1062.

jljorgenson18 commented 3 years ago

@ArtemGovorov Everything seems to be working perfectly now. Thank you so much!

trajano commented 10 months ago

@ArtemGovorov do you have the specific PR or commit that fixes the issue? I am experiencing it as well but with Expo

ArtemGovorov commented 10 months ago

@trajano Please create a separate issue and provide the details requested in the new issue template, we are happy to take a look and investigate.