wallabyjs / public

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

`postprocessor` is not called with Jest 27 + `autoDetect` #2900

Closed Cerberus closed 2 years ago

Cerberus commented 2 years ago

postprocessor is not called with custom wallaby.js (Jest 27 + autoDetect).

Wallaby diagnostics report

{
  editorVersion: '1.63.2',
  pluginVersion: '1.0.322',
  editorType: 'VSCode',
  osVersion: 'darwin 20.4.0',
  nodeVersion: 'v16.13.0',
  coreVersion: '1.0.1206',
  checksum: 'YTQ0NGVmZDU4NzExZWY0MjQ4ZWQ0ZGZiYTJjMjJhZmEsMTY0OTcyMTYwMDAwMCww',
  config: {
    diagnostics: {
      jest: {
        config: {
          configs: [
            {
              automock: false,
              cache: true,
              cacheDirectory: '/private/var/folders/__/sv9x5s6n3fn8kstyj83f693w0000gq/T/jest_dz',
              clearMocks: false,
              coveragePathIgnorePatterns: [ '/node_modules/' ],
              cwd: '<homeDir>/Web/Starter/edge',
              dependencyExtractor: undefined,
              detectLeaks: false,
              detectOpenHandles: false,
              displayName: undefined,
              errorOnDeprecated: false,
              extensionsToTreatAsEsm: [],
              extraGlobals: [],
              filter: undefined,
              forceCoverageMatch: [],
              globalSetup: undefined,
              globalTeardown: undefined,
              globals: { 'ts-jest': { isolatedModules: true } },
              haste: { computeSha1: false, enableSymlinks: false, forceNodeFilesystemAPI: false, throwOnModuleCollision: false },
              injectGlobals: true,
              moduleDirectories: [ 'node_modules', 'src' ],
              moduleFileExtensions: [ 'js', 'jsx', 'ts', 'tsx', 'json', 'node' ],
              moduleLoader: undefined,
              moduleNameMapper: [ [ 'utils/hash', 'utils/hash/node' ] ],
              modulePathIgnorePatterns: [],
              modulePaths: undefined,
              name: '393d78f70267f322ec69b38491c8a944',
              prettierPath: 'prettier',
              resetMocks: false,
              resetModules: false,
              resolver: undefined,
              restoreMocks: false,
              rootDir: '<homeDir>/Web/Starter/edge',
              roots: [ '<homeDir>/Web/Starter/edge' ],
              runner: '<homeDir>/Web/Starter/edge/node_modules/jest-runner/build/index.js',
              setupFiles: [],
              setupFilesAfterEnv: [ '<homeDir>/Web/Starter/edge/src/setupTests.ts' ],
              skipFilter: false,
              skipNodeResolution: undefined,
              slowTestThreshold: 5,
              snapshotFormat: undefined,
              snapshotResolver: undefined,
              snapshotSerializers: [],
              testEnvironment: '<homeDir>/Web/Starter/edge/node_modules/jest-environment-node/build/index.js',
              testEnvironmentOptions: {},
              testLocationInResults: false,
              testMatch: [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)' ],
              testPathIgnorePatterns: [ '/node_modules/' ],
              testRegex: [],
              testRunner: '<homeDir>/Web/Starter/edge/node_modules/jest-circus/runner.js',
              testURL: 'http://localhost',
              timers: 'real',
              transform: [ [ '^.+\\.tsx?$', '<homeDir>/Web/Starter/edge/node_modules/ts-jest/dist/index.js', {} ] ],
              transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ],
              unmockedModulePathPatterns: undefined,
              watchPathIgnorePatterns: []
            }
          ],
          globalConfig: {
            bail: 0,
            changedFilesWithAncestor: false,
            changedSince: undefined,
            collectCoverage: false,
            collectCoverageFrom: [],
            collectCoverageOnlyFrom: undefined,
            coverageDirectory: '<homeDir>/Web/Starter/edge/coverage',
            coverageProvider: 'babel',
            coverageReporters: [ 'json', 'text', 'lcov', 'clover' ],
            coverageThreshold: undefined,
            detectLeaks: false,
            detectOpenHandles: false,
            errorOnDeprecated: false,
            expand: false,
            filter: undefined,
            findRelatedTests: false,
            forceExit: false,
            globalSetup: undefined,
            globalTeardown: undefined,
            json: false,
            lastCommit: false,
            listTests: false,
            logHeapUsage: false,
            maxConcurrency: 5,
            maxWorkers: 11,
            noSCM: undefined,
            noStackTrace: false,
            nonFlagArgs: undefined,
            notify: false,
            notifyMode: 'failure-change',
            onlyChanged: false,
            onlyFailures: false,
            outputFile: undefined,
            passWithNoTests: false,
            projects: [],
            replname: undefined,
            reporters: undefined,
            rootDir: '<homeDir>/Web/Starter/edge',
            runTestsByPath: false,
            silent: undefined,
            skipFilter: false,
            snapshotFormat: undefined,
            testFailureExitCode: 1,
            testNamePattern: undefined,
            testPathPattern: '',
            testResultsProcessor: undefined,
            testSequencer: '<homeDir>/Web/Starter/edge/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: [],
            watchPathIgnorePatterns: [ '/node_modules/', '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/', '/private/var/folders/__/sv9x5s6n3fn8kstyj83f693w0000gq/T/jest_dz', '\\./coverage' ],
            testPathIgnorePatterns: [ '/node_modules/', '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/', '/private/var/folders/__/sv9x5s6n3fn8kstyj83f693w0000gq/T/jest_dz', '\\./coverage' ],
            testMatch: [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)' ],
            testRegex: []
          }
        }
      }
    },
    filesWithCoverageCalculated: [],
    filesWithNoCoverageCalculated: [],
    globalSetup: false,
    testFramework: { version: 'jest@24.8.0', configurator: 'jest@24.8.0', reporter: 'jest@24.8.0', starter: 'jest@24.8.0', autoDetected: true },
    micromatch: true,
    files: [
      { pattern: '/node_modules/', regexp: /\/node_modules\//, ignore: true, trigger: true, load: true },
      { pattern: '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/', regexp: /\.\/dist\/|\.\/build\/|\.\/coverage\/|\.\/git\/|\/\..+\//, ignore: true, trigger: true, load: true },
      {
        pattern: '/private/var/folders/__/sv9x5s6n3fn8kstyj83f693w0000gq/T/jest_dz',
        regexp: /\/private\/var\/folders\/__\/sv9x5s6n3fn8kstyj83f693w0000gq\/T\/jest_dz/,
        ignore: true,
        trigger: true,
        load: true
      },
      { pattern: '\\./coverage', regexp: /\.\/coverage/, ignore: true, trigger: true, load: true },
      { pattern: '**/**', ignore: false, trigger: true, load: true, order: 1 },
      { pattern: '**/__tests__/**/*.[jt]s?(x)', ignore: true, trigger: true, load: true },
      { pattern: '**/?(*.)+(spec|test).[tj]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/|\\./git/|/\\..+/',
        regexp: /\.\/dist\/|\.\/build\/|\.\/coverage\/|\.\/git\/|\/\..+\//,
        ignore: true,
        trigger: true,
        load: true,
        test: true
      },
      {
        pattern: '/private/var/folders/__/sv9x5s6n3fn8kstyj83f693w0000gq/T/jest_dz',
        regexp: /\/private\/var\/folders\/__\/sv9x5s6n3fn8kstyj83f693w0000gq\/T\/jest_dz/,
        ignore: true,
        trigger: true,
        load: true,
        test: true
      },
      { pattern: '\\./coverage', regexp: /\.\/coverage/, ignore: true, trigger: true, load: true, test: true },
      { pattern: '**/__tests__/**/*.[jt]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 2 },
      { pattern: '**/?(*.)+(spec|test).[tj]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 3 }
    ],
    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: '<homeDir>/.nvm/versions/node/v16.13.0/bin/node', viewportSize: { width: 800, height: 600 }, options: { width: 800, height: 600 }, bundle: true },
    reportUnhandledPromises: true,
    slowTestThreshold: 75,
    lowCoverageThreshold: 80,
    loose: true,
    configCode: "module.exports = (wallaby) => {\n\treturn {\n\t\tautoDetect: true,\n\t\tpostprocessor: (w) => {\n\t\t\tconsole.log('postprocessor is called')\n\t\t\treturn Promise.resolve()\n\t\t},\n\t}\n}\n"
  },
  packageJSON: {
    dependencies: {
      'apollo-reporting-protobuf': '0.6.2',
      'better-npm-run': '0.1.1',
      dataloader: '2.0.0',
      graphql: '15.8.0',
      'graphql-type-json': '0.3.2',
      setimmediate: '^1.0.5',
      'ts-node': '8.8.2',
      typescript: '4.2.4'
    },
    devDependencies: {
      '@luckycatfactory/esbuild-graphql-loader': '3.7.0',
      '@types/graphql': '14.5.0',
      '@types/graphql-type-json': '0.3.2',
      '@types/jest': '27.4.0',
      '@types/uuid': '3.4.6',
      apollo: '2.32.5',
      buffer: '6.0.3',
      esbuild: '^0.12.15',
      'esbuild-plugin-alias': '^0.1.2',
      'esbuild-plugin-replace': '1.1.0',
      'graphql-tools': '8.2.0',
      husky: '1.3.1',
      jest: '27.4.7',
      'lint-staged': '8.1.5',
      miniflare: '2.0.0',
      nexus: '1.1.0',
      prettier: '1.19.1',
      'ts-jest': '27.1.2'
    }
  },
  fs: { numberOfFiles: 113 },
  debug: [
    '2022-01-08T12:09:38.710Z angular/cli config Angular CLI not found.\n',
    '2022-01-08T12:09:38.853Z jest/config Detected Jest.\n',
    '2022-01-08T12:09:38.853Z jest/config Configured Jest.\n',
    '2022-01-08T12:09:38.854Z project Wallaby Node version: v16.13.0\n',
    '2022-01-08T12:09:38.854Z project Wallaby config: <homeDir>/Web/Starter/edge/wallaby.js\n',
    '2022-01-08T12:09:38.941Z project File cache: <homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.322/projects/014810374fc921e4\n',
    '2022-01-08T12:09:39.029Z uiService Listening port 51235\n',
    '2022-01-08T12:09:39.038Z project Config file change detected, invalidating local cache\n',
    '2022-01-08T12:09:39.067Z workers Parallelism for initial run: 10, for regular run: 5\n',
    '2022-01-08T12:09:39.067Z workers Starting run worker instance #0\n',
    '2022-01-08T12:09:39.068Z workers Starting run worker instance #1\n',
    '2022-01-08T12:09:39.068Z workers Starting run worker instance #2\n',
    '2022-01-08T12:09:39.068Z workers Starting run worker instance #3\n',
    '2022-01-08T12:09:39.068Z workers Starting run worker instance #4\n',
    '2022-01-08T12:09:39.068Z workers Starting run worker instance #5\n',
    '2022-01-08T12:09:39.068Z workers Starting run worker instance #6\n',
    '2022-01-08T12:09:39.068Z workers Starting run worker instance #7\n',
    '2022-01-08T12:09:39.068Z workers Starting run worker instance #8\n',
    '2022-01-08T12:09:39.068Z workers Starting run worker instance #9\n',
    '2022-01-08T12:09:39.068Z workers Web server is listening at 51906\n',
    '2022-01-08T12:09:39.069Z project File cache requires some updates, waiting required files from IDE\n',
    '2022-01-08T12:09:39.223Z project Stopping process pool\n',
    '2022-01-08T12:09:39.224Z project Promoting test run to full run because of test selection changes\n',
    '2022-01-08T12:09:39.224Z project Test run started; run priority: 3\n',
    '2022-01-08T12:09:39.225Z project Running all tests\n',
    '2022-01-08T12:09:39.227Z workers Starting test run, priority: 3\n',
    '2022-01-08T12:09:39.227Z nodeRunner Starting sandbox [worker #0, session #ja47h]\n',
    '2022-01-08T12:09:39.227Z nodeRunner Preparing sandbox [worker #0, session #ja47h]\n',
    '2022-01-08T12:09:39.249Z workers Started run worker instance (delayed) #2\n',
    '2022-01-08T12:09:39.279Z workers Started run worker instance (delayed) #0\n',
    '2022-01-08T12:09:39.280Z nodeRunner Prepared sandbox [worker #0, session #ja47h]\n',
    '2022-01-08T12:09:39.280Z workers [worker #0, session #ja47h] Running tests in sandbox\n',
    '2022-01-08T12:09:39.281Z workers Started run worker instance (delayed) #3\n',
    '2022-01-08T12:09:39.297Z workers Started run worker instance (delayed) #1\n',
    '2022-01-08T12:09:39.298Z workers Started run worker instance (delayed) #4\n',
    '2022-01-08T12:09:39.312Z workers Started run worker instance (delayed) #5\n',
    '2022-01-08T12:09:39.330Z workers Started run worker instance (delayed) #6\n',
    '2022-01-08T12:09:39.334Z workers Started run worker instance (delayed) #8\n',
    '2022-01-08T12:09:39.335Z workers Started run worker instance (delayed) #7\n',
    '2022-01-08T12:09:39.343Z workers Started run worker instance (delayed) #9\n',
    '2022-01-08T12:09:41.269Z workers Scheduling Jest Test Run (ja47h): 2022-01-08T12:09:40.264Z\n',
    '2022-01-08T12:09:41.298Z workers [ja47h] Loaded unknown number of test(s)\n',
    '2022-01-08T12:09:41.378Z workers [ja47h] Test executed: BUSINESS\n',
    '2022-01-08T12:09:41.381Z workers [ja47h] Run 1 test(s), skipped 0 test(s)\n',
    '2022-01-08T12:09:41.381Z workers Jest Test Run Complete (ja47h): 2022-01-08T12:09:41.377Z\n',
    '2022-01-08T12:09:41.382Z workers [ja47h] Sandbox is responsive, closing it\n',
    '2022-01-08T12:09:41.383Z project Test run finished\n',
    '2022-01-08T12:09:41.383Z project Processed console.log entries\n',
    '2022-01-08T12:09:41.383Z project Processed loading sequences\n',
    '2022-01-08T12:09:41.384Z project Processed executed tests\n',
    '2022-01-08T12:09:41.385Z project Processed code coverage\n',
    '2022-01-08T12:09:41.394Z project Test run result processed and sent to IDE\n'
  ]
}

–––

Try another config:

If I remove autoDetect and set wallaby config like this..

env: {
    type: 'node',
    params: {
        runner: '--experimental-vm-modules',
    },
},
testFramework: 'jest',

postprocessor is called, but got an internal error instead

Debugging Output:

[Info]​ Error: Cannot find Jest test runner
​[Info]​     at Object.<anonymous> (/Users/L/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.322/wallabyb955e0/runners/node/jest@0.4.3/initializer.js:312:9)

Seem like not support jest v27, but v26 work fine.

Please help me check on this case. : )

–– More Info: wallaby core: v1.0.1206, OS: OSX

Cerberus commented 2 years ago

If specific jest-cli like this..

testFramework: {
    type: 'jest',
    path: './node_modules/jest-cli',
},

It will throw another error.

[Info]​ TypeError: Cannot read properties of undefined (reading '_loadConfigDependencies')
​[Info]​     at Object.<anonymous> (/Users/L/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.322/wallabyb955e0/runners/node/jest@0.4.3/initializer.js:621:25)
ArtemGovorov commented 2 years ago

The postprocessor is not called with Jest 27 + autoDetect by design. With autoDetect Wallaby is using Jest's pipeline of transformers and setup files and not using file postprocessor at all (this way your test setup is guaranteed to work in both Wallaby and Jest CLI).

If you can let us know how/for what purposes you have been planning to use postprocessor, we are happy to try to recommend native Jest pipeline way of doing it.

Cerberus commented 2 years ago

Personally I am using postprocessor to make .wasm file (that binding with JS) before running tests. Such as AssemblyScript. It's really useful for me.

Cerberus commented 2 years ago

Finally, I found the root cause.

As I tried a custom wallaby.js with testFramework: 'jest'(v27), the wallaby core will internally resolve jest@0.4.3 (legacy).

So, just specify the version and everything works like a charm again.

testFramework: 'jest@24.8.0'

Have A Good Time for CODING!! : )

letehaha commented 1 year ago

@Cerberus I'm trying to specify testFramework: 'jest@27.0.6' and it says that Test framework [jest@27.0.6] is not supported​​. But it seems to be supported for jest@24.8.0 because it doesn't throw such an error, and trying to reach this version of Jest.

Did I understand correctly that firstly you tried jest v27, but downgraded to jest@24.8.0 to make it work with testFramework?

smcenlly commented 1 year ago

@letehaha - Wallaby's testFramework property versioning is our internal integration version and does not relate to the version of jest you are using. I believe that @Cerberus was using jest@27.4.7 and setting their Wallaby testFramework to jest@24.8.0 (this is our internal integration version number).

Having said that, if you need to set this version, it sounds like you may be doing something wrong. As @ArtemGovorov said above:

Jest 27+ uses autoDetect by design. With autoDetect Wallaby is using Jest's pipeline of transformers and setup files and not using file postprocessor at all (this way your test setup is guaranteed to work in both Wallaby and Jest CLI).

Please let us know why you Jest Automatic Configuration is not working for you as we may be able to recommend a different (better) approach.

Cerberus commented 1 year ago

@letehaha, as he said above. package.json

"jest": "27.4.7",

wallaby.js

testFramework: 'jest@24.8.0',
letehaha commented 1 year ago

@smcenlly tbh I'm probably stuck in another place. I'm using a postprocessor to use custom webpack config, and when I'm passing testFramework.configFile I'm getting ​​[Error] Failed to load configuration file: TypeError: Cannot read properties of undefined (reading 'indexOf')​​. That's what I'm trying to fix, so I tried to use different approaches, because I think that I'm doing something wrong.

That's the Wallaby's config I have:

const webpackConfig = require('./compiler/web')[0]

module.exports = function (wallaby) {
    return {
        // set `load: false` to all source files and tests processed by webpack
        // (except external files),
        // as they should not be loaded in browser,
        // their wrapped versions will be loaded instead
        files: [
            { pattern: 'client/src/**/*.+(js|vue)', load: false },
        ],
        tests: [
            { pattern: 'client/test/unit/**/*.spec.js', load: false },
        ],
        testFramework: {
            configFile: './client/test/unit/jest.config.js',
        },
        postprocessor: wallaby.postprocessors.webpack(webpackConfig),
    }
}
smcenlly commented 1 year ago

@letehaha - I think it's best to create a new issue for your problem.

Can you please describe your project and how you are running tests outside of Wallaby? You mention webpack, but I can also see jest in your configuration. Is it possible for you to provide a sample project with the same dependencies so we can examine your tech stack and see your tests working from the CLI?

letehaha commented 1 year ago

Thanks @smcenlly, created this ticket https://github.com/wallabyjs/public/issues/3169