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

lerna 4 yarn 2, not resolving correctly #2733

Closed
kvernon opened this issue Jun 16, 2021 · 22 comments
Closed

lerna 4 yarn 2, not resolving correctly #2733

kvernon opened this issue Jun 16, 2021 · 22 comments

Comments

@kvernon
Copy link

kvernon commented Jun 16, 2021

Lerna@4 and Yarn@2 (berry) + Wallabyjs not Playing nice

Howdy crew at WallabyJs,

You've all helped me in the past with great ease. and I'm hoping the same will hold true this time. I've taken your advice over setting up NX and also had it applied to Lerna with NPM (thank you for your help again).

My issue is that we're transitioning to from NPM 6x to Yarn 2.

First of all, I've followed these strategies:

Yarn2: https://wallabyjs.com/docs/integration/yarn2.html
Reference to jest.config help: #2657 (comment)

First my wallaby setup:

module.exports = () => ({
  autoDetect: true,
  files: [
    '!**/packages/tests/integration/**/*',
    { pattern: 'node_modules/@company/**', ignore: true }
  ],
  tests: [
    '**/tests/unit/**/*.test.*'
  ],
  testFramework: {
    // the jest configuration file path
    // (relative to project root)
    configFile: './jest.config.js'
  },
  debug: true
});

I tried to get away from node_modules/@company ... and failed

I've got an isolated config like so:

module.exports = {
  rootDir: '.',
  preset: './jest.unit.preset.js',
  projects: [
    '<rootDir>/packages/npm-scripts/jest.config.js',
    '<rootDir>/packages/core-sdk/jest.config.js',
    '<rootDir>/packages/http-client-sdk/jest.config.js',
    '<rootDir>/packages/logging-sdk/jest.config.js',
    '<rootDir>/packages/testing/jest.config.js',
    '<rootDir>/packages/utils-sdk/jest.config.js'
  ],
  coverageDirectory: './coverage/all'
};

I get a long list of items where it tries to use the import statement outside of the module (from failing tests log tab in Webstorm):

Cannot use import statement outside a module
	at node_modules/@company/core-sdk/tests/unit/constants/headers-constants.test.ts:1

Cannot use import statement outside a module
	at node_modules/@company/core-sdk/tests/unit/errors/core-service-error.test.ts:1
...

package.json

{
  "scripts": {
    "test:root": "jest --detectOpenHandles",
  }, 
  "devDependencies": {
    "@commitlint/cli": "^12.1.4",
    "@commitlint/config-conventional": "^12.1.4",
    "@commitlint/config-lerna-scopes": "^12.1.4",
    "@commitlint/prompt-cli": "^12.1.4",
    "@typescript-eslint/eslint-plugin": "^4.26.1",
    "@typescript-eslint/parser": "^4.26.1",
    "commitlint-config-jira": "^1.5.1",
    "commitlint-plugin-jira-rules": "^1.5.1",
    "conventional-changelog-conventionalcommits": "^4.6.0",
    "cz-conventional-changelog": "^3.3.0",
    "eslint": "^7.28.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^3.4.0",
    "format-package": "^6.1.0",
    "husky": "^6.0.0",
    "lerna": "^4.0.0",
    "lerna-add-many": "^1.0.0",
    "lint-staged": "^11.0.0",
    "npm-run-all": "^4.1.5",
    "prettier": "^2.3.1",
    "pretty-quick": "^3.1.0",
    "rimraf": "^3.0.2",
    "use-yarn": "^2.2.0"
  }
}

Now if run this using from the above using: > yarn run test:root I have everything running as a successful scenario directly from CLI

Wallaby diagnostics report

{
  editorVersion: 'WebStorm 2021.1.2',
  pluginVersion: '1.0.216',
  editorType: 'IntelliJ',
  osVersion: 'darwin 19.6.0',
  nodeVersion: 'v14.17.1',
  coreVersion: '1.0.1096',
  checksum: 'ZWRmZDMxZGRhM2RlY2YwZWI0ZDllMjFkZDRkMGI5OGQsMTY0NzkwNzIwMDAwMCww',
  config: {
    files: [ { pattern: '**/packages/tests/integration/**/*', ignore: true, trigger: true, load: true }, { pattern: 'node_modules/@company/**', ignore: true, trigger: true, load: true } ],
    tests: [ { pattern: '**/tests/unit/**/*.test.*', ignore: false, trigger: true, load: true, test: true, order: 1 } ],
    testFramework: { version: 'jest@24.8.0', configurator: 'jest@24.8.0', reporter: 'jest@24.8.0', starter: 'jest@24.8.0', configFile: './jest.config.js', autoDetected: true },
    debug: true,
    diagnostics: {
      jest: {
        config: {
          configs: [
            {
              automock: false,
              cache: true,
              cacheDirectory: '/private/var/folders/w8/h8q2_7l960v4y9nt4lb75g3jj212w9/T/jest_r85x8p',
              clearMocks: false,
              coveragePathIgnorePatterns: [ '/node_modules/' ],
              cwd: '<homeDir>/work-git/api-project-yarn',
              dependencyExtractor: undefined,
              detectLeaks: false,
              detectOpenHandles: false,
              displayName: { color: 'white', name: 'npm-scripts' },
              errorOnDeprecated: false,
              extensionsToTreatAsEsm: [],
              extraGlobals: [],
              filter: undefined,
              forceCoverageMatch: [],
              globalSetup: undefined,
              globalTeardown: undefined,
              globals: {},
              haste: { computeSha1: false, enableSymlinks: false, forceNodeFilesystemAPI: false, throwOnModuleCollision: false },
              injectGlobals: true,
              moduleDirectories: [ 'node_modules' ],
              moduleFileExtensions: [ 'js', 'jsx', 'ts', 'tsx', 'json', 'node' ],
              moduleLoader: undefined,
              moduleNameMapper: [],
              modulePathIgnorePatterns: [],
              modulePaths: undefined,
              name: '24ea9566c783f8b9633f787e24747fcf',
              prettierPath: 'prettier',
              resetMocks: false,
              resetModules: false,
              resolver: undefined,
              restoreMocks: false,
              rootDir: '<homeDir>/work-git/api-project-yarn/packages/npm-scripts',
              roots: [ '<homeDir>/work-git/api-project-yarn/packages/npm-scripts' ],
              runner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-runner/build/index.js',
              setupFiles: [],
              setupFilesAfterEnv: [],
              skipFilter: false,
              skipNodeResolution: undefined,
              slowTestThreshold: 5,
              snapshotResolver: undefined,
              snapshotSerializers: [],
              testEnvironment: '<homeDir>/work-git/api-project-yarn/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>/work-git/api-project-yarn/node_modules/jest-circus/runner.js',
              testURL: 'http://localhost',
              timers: 'real',
              transform: [ [ '\\.[jt]sx?$', '<homeDir>/work-git/api-project-yarn/node_modules/babel-jest/build/index.js', {} ] ],
              transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ],
              unmockedModulePathPatterns: undefined,
              watchPathIgnorePatterns: []
            },
            {
              automock: false,
              cache: true,
              cacheDirectory: '/private/var/folders/w8/h8q2_7l960v4y9nt4lb75g3jj212w9/T/jest_r85x8p',
              clearMocks: false,
              coveragePathIgnorePatterns: [ '/node_modules/' ],
              cwd: '<homeDir>/work-git/api-project-yarn',
              dependencyExtractor: undefined,
              detectLeaks: false,
              detectOpenHandles: false,
              displayName: { color: 'white', name: '@company/core-sdk' },
              errorOnDeprecated: false,
              extensionsToTreatAsEsm: [],
              extraGlobals: [],
              filter: undefined,
              forceCoverageMatch: [],
              globalSetup: undefined,
              globalTeardown: undefined,
              globals: { 'ts-jest': { tsconfig: '<rootDir>/tsconfig.json' } },
              haste: { computeSha1: false, enableSymlinks: false, forceNodeFilesystemAPI: false, throwOnModuleCollision: false },
              injectGlobals: true,
              moduleDirectories: [ 'node_modules' ],
              moduleFileExtensions: [ 'js', 'ts' ],
              moduleLoader: undefined,
              moduleNameMapper: [ [ '^@company/(.*)$', '<homeDir>/work-git/api-project-yarn/packages/$1/lib' ] ],
              modulePathIgnorePatterns: [],
              modulePaths: undefined,
              name: '89e9d9d68b07589162dd9c985fab711c',
              prettierPath: 'prettier',
              resetMocks: false,
              resetModules: false,
              resolver: undefined,
              restoreMocks: false,
              rootDir: '<homeDir>/work-git/api-project-yarn/packages/core-sdk',
              roots: [ '<homeDir>/work-git/api-project-yarn/packages/core-sdk' ],
              runner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-runner/build/index.js',
              setupFiles: [],
              setupFilesAfterEnv: [],
              skipFilter: false,
              skipNodeResolution: undefined,
              slowTestThreshold: 5,
              snapshotResolver: undefined,
              snapshotSerializers: [],
              testEnvironment: '<homeDir>/work-git/api-project-yarn/node_modules/jest-environment-node/build/index.js',
              testEnvironmentOptions: {},
              testLocationInResults: false,
              testMatch: [ '**/unit/**/?(*.)+(spec|test).[jt]s?(x)' ],
              testPathIgnorePatterns: [ '/node_modules/' ],
              testRegex: [],
              testRunner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-circus/runner.js',
              testURL: 'http://localhost',
              timers: 'real',
              transform: [ [ '^.+\\.(ts)$', '<homeDir>/work-git/api-project-yarn/node_modules/ts-jest/dist/index.js', {} ] ],
              transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ],
              unmockedModulePathPatterns: undefined,
              watchPathIgnorePatterns: []
            },
            {
              automock: false,
              cache: true,
              cacheDirectory: '/private/var/folders/w8/h8q2_7l960v4y9nt4lb75g3jj212w9/T/jest_r85x8p',
              clearMocks: false,
              coveragePathIgnorePatterns: [ '/node_modules/' ],
              cwd: '<homeDir>/work-git/api-project-yarn',
              dependencyExtractor: undefined,
              detectLeaks: false,
              detectOpenHandles: false,
              displayName: { color: 'white', name: '@company/http-client-sdk' },
              errorOnDeprecated: false,
              extensionsToTreatAsEsm: [],
              extraGlobals: [],
              filter: undefined,
              forceCoverageMatch: [],
              globalSetup: undefined,
              globalTeardown: undefined,
              globals: { 'ts-jest': { tsconfig: '<rootDir>/tsconfig.json' } },
              haste: { computeSha1: false, enableSymlinks: false, forceNodeFilesystemAPI: false, throwOnModuleCollision: false },
              injectGlobals: true,
              moduleDirectories: [ 'node_modules' ],
              moduleFileExtensions: [ 'js', 'ts' ],
              moduleLoader: undefined,
              moduleNameMapper: [ [ '^@company/(.*)$', '<homeDir>/work-git/api-project-yarn/packages/$1/lib' ] ],
              modulePathIgnorePatterns: [],
              modulePaths: undefined,
              name: '3f3bb5486392eedeb55f5df86dec2503',
              prettierPath: 'prettier',
              resetMocks: false,
              resetModules: false,
              resolver: undefined,
              restoreMocks: false,
              rootDir: '<homeDir>/work-git/api-project-yarn/packages/http-client-sdk',
              roots: [ '<homeDir>/work-git/api-project-yarn/packages/http-client-sdk' ],
              runner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-runner/build/index.js',
              setupFiles: [],
              setupFilesAfterEnv: [],
              skipFilter: false,
              skipNodeResolution: undefined,
              slowTestThreshold: 5,
              snapshotResolver: undefined,
              snapshotSerializers: [],
              testEnvironment: '<homeDir>/work-git/api-project-yarn/node_modules/jest-environment-node/build/index.js',
              testEnvironmentOptions: {},
              testLocationInResults: false,
              testMatch: [ '**/unit/**/?(*.)+(spec|test).[jt]s?(x)' ],
              testPathIgnorePatterns: [ '/node_modules/' ],
              testRegex: [],
              testRunner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-circus/runner.js',
              testURL: 'http://localhost',
              timers: 'real',
              transform: [ [ '^.+\\.(ts)$', '<homeDir>/work-git/api-project-yarn/node_modules/ts-jest/dist/index.js', {} ] ],
              transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ],
              unmockedModulePathPatterns: undefined,
              watchPathIgnorePatterns: []
            },
            {
              automock: false,
              cache: true,
              cacheDirectory: '/private/var/folders/w8/h8q2_7l960v4y9nt4lb75g3jj212w9/T/jest_r85x8p',
              clearMocks: false,
              coveragePathIgnorePatterns: [ '/node_modules/' ],
              cwd: '<homeDir>/work-git/api-project-yarn',
              dependencyExtractor: undefined,
              detectLeaks: false,
              detectOpenHandles: false,
              displayName: { color: 'white', name: '@company/logging-sdk' },
              errorOnDeprecated: false,
              extensionsToTreatAsEsm: [],
              extraGlobals: [],
              filter: undefined,
              forceCoverageMatch: [],
              globalSetup: undefined,
              globalTeardown: undefined,
              globals: { 'ts-jest': { tsconfig: '<rootDir>/tsconfig.json' } },
              haste: { computeSha1: false, enableSymlinks: false, forceNodeFilesystemAPI: false, throwOnModuleCollision: false },
              injectGlobals: true,
              moduleDirectories: [ 'node_modules' ],
              moduleFileExtensions: [ 'js', 'ts' ],
              moduleLoader: undefined,
              moduleNameMapper: [ [ '^@company/(.*)$', '<homeDir>/work-git/api-project-yarn/packages/$1/lib' ] ],
              modulePathIgnorePatterns: [],
              modulePaths: undefined,
              name: '2614638ed800b19f7b150419fda0ba03',
              prettierPath: 'prettier',
              resetMocks: false,
              resetModules: false,
              resolver: undefined,
              restoreMocks: false,
              rootDir: '<homeDir>/work-git/api-project-yarn/packages/logging-sdk',
              roots: [ '<homeDir>/work-git/api-project-yarn/packages/logging-sdk' ],
              runner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-runner/build/index.js',
              setupFiles: [],
              setupFilesAfterEnv: [],
              skipFilter: false,
              skipNodeResolution: undefined,
              slowTestThreshold: 5,
              snapshotResolver: undefined,
              snapshotSerializers: [],
              testEnvironment: '<homeDir>/work-git/api-project-yarn/node_modules/jest-environment-node/build/index.js',
              testEnvironmentOptions: {},
              testLocationInResults: false,
              testMatch: [ '**/unit/**/?(*.)+(spec|test).[jt]s?(x)' ],
              testPathIgnorePatterns: [ '/node_modules/' ],
              testRegex: [],
              testRunner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-circus/runner.js',
              testURL: 'http://localhost',
              timers: 'real',
              transform: [ [ '^.+\\.(ts)$', '<homeDir>/work-git/api-project-yarn/node_modules/ts-jest/dist/index.js', {} ] ],
              transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ],
              unmockedModulePathPatterns: undefined,
              watchPathIgnorePatterns: []
            },
            {
              automock: false,
              cache: true,
              cacheDirectory: '/private/var/folders/w8/h8q2_7l960v4y9nt4lb75g3jj212w9/T/jest_r85x8p',
              clearMocks: false,
              coveragePathIgnorePatterns: [ '/node_modules/' ],
              cwd: '<homeDir>/work-git/api-project-yarn',
              dependencyExtractor: undefined,
              detectLeaks: false,
              detectOpenHandles: false,
              displayName: { color: 'white', name: '@company/testing' },
              errorOnDeprecated: false,
              extensionsToTreatAsEsm: [],
              extraGlobals: [],
              filter: undefined,
              forceCoverageMatch: [],
              globalSetup: undefined,
              globalTeardown: undefined,
              globals: { 'ts-jest': { tsconfig: '<rootDir>/tsconfig.json' } },
              haste: { computeSha1: false, enableSymlinks: false, forceNodeFilesystemAPI: false, throwOnModuleCollision: false },
              injectGlobals: true,
              moduleDirectories: [ 'node_modules' ],
              moduleFileExtensions: [ 'js', 'ts' ],
              moduleLoader: undefined,
              moduleNameMapper: [ [ '^@company/(.*)$', '<homeDir>/work-git/api-project-yarn/packages/$1/lib' ] ],
              modulePathIgnorePatterns: [],
              modulePaths: undefined,
              name: 'e2cee00f2c532016299317e8290f1bdb',
              prettierPath: 'prettier',
              resetMocks: false,
              resetModules: false,
              resolver: undefined,
              restoreMocks: false,
              rootDir: '<homeDir>/work-git/api-project-yarn/packages/testing',
              roots: [ '<homeDir>/work-git/api-project-yarn/packages/testing' ],
              runner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-runner/build/index.js',
              setupFiles: [],
              setupFilesAfterEnv: [],
              skipFilter: false,
              skipNodeResolution: undefined,
              slowTestThreshold: 5,
              snapshotResolver: undefined,
              snapshotSerializers: [],
              testEnvironment: '<homeDir>/work-git/api-project-yarn/node_modules/jest-environment-node/build/index.js',
              testEnvironmentOptions: {},
              testLocationInResults: false,
              testMatch: [ '**/unit/**/?(*.)+(spec|test).[jt]s?(x)' ],
              testPathIgnorePatterns: [ '/node_modules/' ],
              testRegex: [],
              testRunner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-circus/runner.js',
              testURL: 'http://localhost',
              timers: 'real',
              transform: [ [ '^.+\\.(ts)$', '<homeDir>/work-git/api-project-yarn/node_modules/ts-jest/dist/index.js', {} ] ],
              transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ],
              unmockedModulePathPatterns: undefined,
              watchPathIgnorePatterns: []
            },
            {
              automock: false,
              cache: true,
              cacheDirectory: '/private/var/folders/w8/h8q2_7l960v4y9nt4lb75g3jj212w9/T/jest_r85x8p',
              clearMocks: false,
              coveragePathIgnorePatterns: [ '/node_modules/' ],
              cwd: '<homeDir>/work-git/api-project-yarn',
              dependencyExtractor: undefined,
              detectLeaks: false,
              detectOpenHandles: false,
              displayName: { color: 'white', name: '@company/utils-sdk' },
              errorOnDeprecated: false,
              extensionsToTreatAsEsm: [],
              extraGlobals: [],
              filter: undefined,
              forceCoverageMatch: [],
              globalSetup: undefined,
              globalTeardown: undefined,
              globals: { 'ts-jest': { tsconfig: '<rootDir>/tsconfig.json' } },
              haste: { computeSha1: false, enableSymlinks: false, forceNodeFilesystemAPI: false, throwOnModuleCollision: false },
              injectGlobals: true,
              moduleDirectories: [ 'node_modules' ],
              moduleFileExtensions: [ 'js', 'ts' ],
              moduleLoader: undefined,
              moduleNameMapper: [ [ '^@company/(.*)$', '<homeDir>/work-git/api-project-yarn/packages/$1/lib' ] ],
              modulePathIgnorePatterns: [],
              modulePaths: undefined,
              name: 'b0a23b2426889562013334f8b9da2f4a',
              prettierPath: 'prettier',
              resetMocks: false,
              resetModules: false,
              resolver: undefined,
              restoreMocks: false,
              rootDir: '<homeDir>/work-git/api-project-yarn/packages/utils-sdk',
              roots: [ '<homeDir>/work-git/api-project-yarn/packages/utils-sdk' ],
              runner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-runner/build/index.js',
              setupFiles: [],
              setupFilesAfterEnv: [],
              skipFilter: false,
              skipNodeResolution: undefined,
              slowTestThreshold: 5,
              snapshotResolver: undefined,
              snapshotSerializers: [],
              testEnvironment: '<homeDir>/work-git/api-project-yarn/node_modules/jest-environment-node/build/index.js',
              testEnvironmentOptions: {},
              testLocationInResults: false,
              testMatch: [ '**/unit/**/?(*.)+(spec|test).[jt]s?(x)' ],
              testPathIgnorePatterns: [ '/node_modules/' ],
              testRegex: [],
              testRunner: '<homeDir>/work-git/api-project-yarn/node_modules/jest-circus/runner.js',
              testURL: 'http://localhost',
              timers: 'real',
              transform: [ [ '^.+\\.(ts)$', '<homeDir>/work-git/api-project-yarn/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>/work-git/api-project-yarn/coverage/all',
            coverageProvider: 'babel',
            coverageReporters: [ 'lcov', 'text' ],
            coverageThreshold: { global: { branches: 90, functions: 90, lines: 90, statements: 90 } },
            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: [
              '<homeDir>/work-git/api-project-yarn/packages/npm-scripts/jest.config.js',
              '<homeDir>/work-git/api-project-yarn/packages/core-sdk/jest.config.js',
              '<homeDir>/work-git/api-project-yarn/packages/http-client-sdk/jest.config.js',
              '<homeDir>/work-git/api-project-yarn/packages/logging-sdk/jest.config.js',
              '<homeDir>/work-git/api-project-yarn/packages/testing/jest.config.js',
              '<homeDir>/work-git/api-project-yarn/packages/utils-sdk/jest.config.js'
            ],
            replname: undefined,
            reporters: undefined,
            rootDir: '<homeDir>/work-git/api-project-yarn',
            runTestsByPath: false,
            silent: true,
            skipFilter: false,
            testFailureExitCode: 1,
            testNamePattern: undefined,
            testPathPattern: '',
            testResultsProcessor: undefined,
            testSequencer: '<homeDir>/work-git/api-project-yarn/node_modules/@jest/test-sequencer/build/index.js',
            testTimeout: undefined,
            updateSnapshot: 'new',
            useStderr: false,
            verbose: false,
            watch: false,
            watchAll: false,
            watchPlugins: undefined,
            watchman: true
          },
          hasDeprecationWarnings: false,
          wallaby: {
            roots: [ 'packages/npm-scripts', 'packages/core-sdk', 'packages/http-client-sdk', 'packages/logging-sdk', 'packages/testing', 'packages/utils-sdk' ],
            watchPathIgnorePatterns: [ '/node_modules/', '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/' ],
            testPathIgnorePatterns: [ '/node_modules/', '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/' ],
            testMatch: [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)', '**/unit/**/?(*.)+(spec|test).[jt]s?(x)' ],
            testRegex: []
          }
        }
      }
    },
    filesWithCoverageCalculated: [],
    filesWithNoCoverageCalculated: [],
    globalSetup: false,
    micromatch: true,
    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/v14.17.1/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 = () => ({\n' +
      '  autoDetect: true,\n' +
      '  files: [\n' +
      "    '!**/packages/tests/integration/**/*',\n" +
      "    { pattern: 'node_modules/@company/**', ignore: true }\n" +
      '  ],\n' +
      '  tests: [\n' +
      "    '**/tests/unit/**/*.test.*'\n" +
      '  ],\n' +
      '  testFramework: {\n' +
      '    // the jest configuration file path\n' +
      '    // (relative to project root)\n' +
      "    configFile: './jest.config.js'\n" +
      '  },\n' +
      '  debug: true\n' +
      '});\n'
  },
  packageJSON: {
    dependencies: undefined,
    devDependencies: {
      '@commitlint/cli': '^12.1.4',
      '@commitlint/config-conventional': '^12.1.4',
      '@commitlint/config-lerna-scopes': '^12.1.4',
      '@commitlint/prompt-cli': '^12.1.4',
      '@typescript-eslint/eslint-plugin': '^4.26.1',
      '@typescript-eslint/parser': '^4.26.1',
      'commitlint-config-jira': '^1.5.1',
      'commitlint-plugin-jira-rules': '^1.5.1',
      'conventional-changelog-conventionalcommits': '^4.6.0',
      'cz-conventional-changelog': '^3.3.0',
      eslint: '^7.28.0',
      'eslint-config-prettier': '^8.3.0',
      'eslint-plugin-prettier': '^3.4.0',
      'format-package': '^6.1.0',
      husky: '^6.0.0',
      lerna: '^4.0.0',
      'lerna-add-many': '^1.0.0',
      'lint-staged': '^11.0.0',
      'npm-run-all': '^4.1.5',
      prettier: '^2.3.1',
      'pretty-quick': '^3.1.0',
      rimraf: '^3.0.2',
      'use-yarn': '^2.2.0'
    }
  },
  fs: { numberOfFiles: 168 },
  debug: [
    '2021-06-16T01:08:07.822Z angular/cli config Angular CLI not found.\n',
    '2021-06-16T01:08:08.040Z jest/config Detected Jest.\n',
    '2021-06-16T01:08:08.042Z jest/config Configured Jest.\n',
    '2021-06-16T01:08:08.043Z project Wallaby Node version: v14.17.1\n',
    '2021-06-16T01:08:08.043Z project Wallaby config: <homeDir>/work-git/api-project-yarn/wallaby.js\n',
    '2021-06-16T01:08:12.353Z project File cache: <homeDir>/Library/Caches/JetBrains/WebStorm2021.1/wallaby/projects/cdcd5915d075ad1b\n',
    '2021-06-16T01:08:12.518Z uiService Listening port 51235\n',
    '2021-06-16T01:08:12.649Z project package.json file change detected, invalidating local cache\n',
    '2021-06-16T01:08:12.743Z workers Parallelism for initial run: 10, for regular run: 5\n',
    '2021-06-16T01:08:12.743Z workers Starting run worker instance #0\n',
    '2021-06-16T01:08:12.743Z workers Starting run worker instance #1\n',
    '2021-06-16T01:08:12.743Z workers Starting run worker instance #2\n',
    '2021-06-16T01:08:12.743Z workers Starting run worker instance #3\n',
    '2021-06-16T01:08:12.744Z workers Starting run worker instance #4\n',
    '2021-06-16T01:08:12.744Z workers Starting run worker instance #5\n',
    '2021-06-16T01:08:12.744Z workers Starting run worker instance #6\n',
    '2021-06-16T01:08:12.744Z workers Starting run worker instance #7\n',
    '2021-06-16T01:08:12.744Z workers Starting run worker instance #8\n',
    '2021-06-16T01:08:12.744Z workers Starting run worker instance #9\n',
    '2021-06-16T01:08:12.744Z workers Web server is listening at 55883\n',
    '2021-06-16T01:08:12.744Z project File cache requires some updates, waiting required files from IDE\n',
    '2021-06-16T01:08:13.106Z workers Started run worker instance (delayed) #0\n',
    '2021-06-16T01:08:13.107Z workers Started run worker instance (delayed) #1\n',
    '2021-06-16T01:08:13.109Z workers Started run worker instance (delayed) #2\n',
    '2021-06-16T01:08:13.110Z workers Started run worker instance (delayed) #3\n',
    '2021-06-16T01:08:13.137Z workers Started run worker instance (delayed) #6\n',
    '2021-06-16T01:08:13.137Z workers Started run worker instance (delayed) #4\n',
    '2021-06-16T01:08:13.145Z workers Started run worker instance (delayed) #5\n',
    '2021-06-16T01:08:13.157Z workers Started run worker instance (delayed) #7\n',
    '2021-06-16T01:08:13.158Z workers Started run worker instance (delayed) #8\n',
    '2021-06-16T01:08:13.163Z workers Started run worker instance (delayed) #9\n',
    '2021-06-16T01:08:13.218Z project Stopping process pool\n',
    '2021-06-16T01:08:13.222Z project Test run started; run priority: 3\n',
    '2021-06-16T01:08:13.223Z project Running all tests\n',
    '2021-06-16T01:08:13.225Z workers Starting test run, priority: 3\n',
    '2021-06-16T01:08:13.225Z workers Distributing tests between 10 workers\n',
    '2021-06-16T01:08:13.229Z workers Running tests in parallel\n',
    '2021-06-16T01:08:13.229Z nodeRunner Starting sandbox [worker #0, session #nu1my]\n',
    '2021-06-16T01:08:13.229Z nodeRunner Starting sandbox [worker #1, session #4yxwq]\n',
    '2021-06-16T01:08:13.229Z nodeRunner Starting sandbox [worker #2, session #z5sd4]\n',
    '2021-06-16T01:08:13.229Z nodeRunner Starting sandbox [worker #3, session #y7tjf]\n',
    '2021-06-16T01:08:13.229Z nodeRunner Starting sandbox [worker #4, session #m9i2h]\n',
    '2021-06-16T01:08:13.229Z nodeRunner Starting sandbox [worker #5, session #4xka7]\n',
    '2021-06-16T01:08:13.229Z nodeRunner Starting sandbox [worker #6, session #g8m3p]\n',
    '2021-06-16T01:08:13.229Z nodeRunner Starting sandbox [worker #7, session #34f9d]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Starting sandbox [worker #8, session #u09wl]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Starting sandbox [worker #9, session #w979e]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Preparing sandbox [worker #0, session #nu1my]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Preparing sandbox [worker #1, session #4yxwq]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Preparing sandbox [worker #2, session #z5sd4]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Preparing sandbox [worker #3, session #y7tjf]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Preparing sandbox [worker #4, session #m9i2h]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Preparing sandbox [worker #5, session #4xka7]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Preparing sandbox [worker #6, session #g8m3p]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Preparing sandbox [worker #7, session #34f9d]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Preparing sandbox [worker #8, session #u09wl]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Preparing sandbox [worker #9, session #w979e]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Prepared sandbox [worker #0, session #nu1my]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Prepared sandbox [worker #1, session #4yxwq]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Prepared sandbox [worker #2, session #z5sd4]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Prepared sandbox [worker #3, session #y7tjf]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Prepared sandbox [worker #4, session #m9i2h]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Prepared sandbox [worker #5, session #4xka7]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Prepared sandbox [worker #6, session #g8m3p]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Prepared sandbox [worker #7, session #34f9d]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Prepared sandbox [worker #8, session #u09wl]\n',
    '2021-06-16T01:08:13.230Z nodeRunner Prepared sandbox [worker #9, session #w979e]\n',
    '2021-06-16T01:08:13.231Z workers [worker #0, session #nu1my] Running tests in sandbox\n',
    '2021-06-16T01:08:13.232Z workers [worker #1, session #4yxwq] Running tests in sandbox\n',
    '2021-06-16T01:08:13.232Z workers [worker #2, session #z5sd4] Running tests in sandbox\n',
    '2021-06-16T01:08:13.233Z workers [worker #3, session #y7tjf] Running tests in sandbox\n',
    '2021-06-16T01:08:13.233Z workers [worker #4, session #m9i2h] Running tests in sandbox\n',
    '2021-06-16T01:08:13.234Z workers [worker #5, session #4xka7] Running tests in sandbox\n',
    '2021-06-16T01:08:13.234Z workers [worker #6, session #g8m3p] Running tests in sandbox\n',
    '2021-06-16T01:08:13.235Z workers [worker #7, session #34f9d] Running tests in sandbox\n',
    '2021-06-16T01:08:13.235Z workers [worker #8, session #u09wl] Running tests in sandbox\n',
    '2021-06-16T01:08:13.235Z workers [worker #9, session #w979e] Running tests in sandbox\n',
    '2021-06-16T01:08:21.030Z workers Some long running code has been detected: one of your tests is taking more than 5000ms to execute.\n',
    '2021-06-16T01:08:25.532Z workers Scheduling Jest Test Run (z5sd4): 2021-06-16T01:08:13.900Z\n',
    '2021-06-16T01:08:25.535Z workers Sandbox (active) [z5sd4] error: Cannot use import statement outside a module\n',
    '2021-06-16T01:08:25.538Z workers [z5sd4] Run 0 test(s), skipped 0 test(s)\n',
    '2021-06-16T01:08:25.691Z workers Jest Test Run Complete (z5sd4): 2021-06-16T01:08:25.531Z\n',
    '2021-06-16T01:08:25.691Z workers [z5sd4] Sandbox is responsive, closing it\n',
    '2021-06-16T01:08:27.287Z workers Scheduling Jest Test Run (y7tjf): 2021-06-16T01:08:13.895Z\n',
    '2021-06-16T01:08:27.298Z workers Sandbox (active) [y7tjf] error: Cannot use import statement outside a module\n',
    '2021-06-16T01:08:27.300Z workers [y7tjf] Run 0 test(s), skipped 0 test(s)\n',
    '2021-06-16T01:08:27.347Z workers Jest Test Run Complete (y7tjf): 2021-06-16T01:08:27.286Z\n',
    '2021-06-16T01:08:27.347Z workers [y7tjf] Sandbox is responsive, closing it\n',
    '2021-06-16T01:08:27.926Z workers Scheduling Jest Test Run (nu1my): 2021-06-16T01:08:13.881Z\n',
    '2021-06-16T01:08:28.318Z workers Scheduling Jest Test Run (4yxwq): 2021-06-16T01:08:13.884Z\n',
    '2021-06-16T01:08:28.320Z workers Sandbox (active) [4yxwq] error: Cannot use import statement outside a module\n',
    '2021-06-16T01:08:28.320Z workers [4yxwq] Run 0 test(s), skipped 0 test(s)\n',
    '2021-06-16T01:08:28.377Z workers Jest Test Run Complete (4yxwq): 2021-06-16T01:08:28.317Z\n',
    '2021-06-16T01:08:28.377Z workers [4yxwq] Sandbox is responsive, closing it\n',
    '2021-06-16T01:08:28.411Z workers Scheduling Jest Test Run (g8m3p): 2021-06-16T01:08:13.887Z\n',
    '2021-06-16T01:08:29.463Z workers Some long running code has been detected: one of your tests is taking more than 5000ms to execute.\n',
    '2021-06-16T01:08:30.001Z workers Scheduling Jest Test Run (u09wl): 2021-06-16T01:08:14.187Z\n',
    '2021-06-16T01:08:30.014Z workers Sandbox (active) [u09wl] error: Cannot use import statement outside a module\n',
    '2021-06-16T01:08:30.014Z workers [u09wl] Run 0 test(s), skipped 0 test(s)\n',
    '2021-06-16T01:08:30.041Z workers Jest Test Run Complete (u09wl): 2021-06-16T01:08:30.012Z\n',
    '2021-06-16T01:08:30.041Z workers [u09wl] Sandbox is responsive, closing it\n',
    '2021-06-16T01:08:30.131Z workers Sandbox (active) [nu1my] error: Cannot use import statement outside a module\n',
    '2021-06-16T01:08:30.134Z workers [nu1my] Run 0 test(s), skipped 0 test(s)\n',
    '2021-06-16T01:08:30.222Z workers Jest Test Run Complete (nu1my): 2021-06-16T01:08:30.127Z\n',
    '2021-06-16T01:08:30.223Z workers [nu1my] Sandbox is responsive, closing it\n',
    '2021-06-16T01:08:30.310Z workers Scheduling Jest Test Run (m9i2h): 2021-06-16T01:08:14.048Z\n',
    '2021-06-16T01:08:30.317Z workers Sandbox (active) [m9i2h] error: Cannot use import statement outside a module\n',
    '2021-06-16T01:08:30.318Z workers [m9i2h] Run 0 test(s), skipped 0 test(s)\n',
    '2021-06-16T01:08:30.372Z workers Jest Test Run Complete (m9i2h): 2021-06-16T01:08:30.313Z\n',
    '2021-06-16T01:08:30.373Z workers [m9i2h] Sandbox is responsive, closing it\n',
    '2021-06-16T01:08:30.540Z workers Scheduling Jest Test Run (w979e): 2021-06-16T01:08:14.232Z\n',
    '2021-06-16T01:08:30.550Z workers Sandbox (active) [w979e] error: Cannot use import statement outside a module\n',
    '2021-06-16T01:08:30.553Z workers [w979e] Run 0 test(s), skipped 0 test(s)\n',
    '2021-06-16T01:08:30.586Z workers Jest Test Run Complete (w979e): 2021-06-16T01:08:30.543Z\n',
    '2021-06-16T01:08:30.587Z workers [w979e] Sandbox is responsive, closing it\n',
    '2021-06-16T01:08:30.658Z workers Scheduling Jest Test Run (34f9d): 2021-06-16T01:08:14.241Z\n',
    '2021-06-16T01:08:31.409Z workers Scheduling Jest Test Run (4xka7): 2021-06-16T01:08:14.051Z\n',
    '2021-06-16T01:08:31.420Z workers Sandbox (active) [4xka7] error: Cannot use import statement outside a module\n',
    '2021-06-16T01:08:31.421Z workers [4xka7] Run 0 test(s), skipped 0 test(s)\n',
    '2021-06-16T01:08:31.468Z workers Jest Test Run Complete (4xka7): 2021-06-16T01:08:31.418Z\n',
    '2021-06-16T01:08:31.468Z workers [4xka7] Sandbox is responsive, closing it\n',
    '2021-06-16T01:08:31.711Z workers Sandbox (active) [g8m3p] error: Cannot use import statement outside a module\n',
    '2021-06-16T01:08:31.711Z workers [g8m3p] Run 0 test(s), skipped 0 test(s)\n',
    '2021-06-16T01:08:31.771Z workers Jest Test Run Complete (g8m3p): 2021-06-16T01:08:31.708Z\n',
    '2021-06-16T01:08:31.771Z workers [g8m3p] Sandbox is responsive, closing it\n',
    '2021-06-16T01:08:32.367Z workers Sandbox (active) [34f9d] error: Cannot use import statement outside a module\n',
    '2021-06-16T01:08:32.367Z workers [34f9d] Run 0 test(s), skipped 0 test(s)\n',
    '2021-06-16T01:08:32.408Z workers Jest Test Run Complete (34f9d): 2021-06-16T01:08:32.365Z\n',
    '2021-06-16T01:08:32.409Z workers [34f9d] Sandbox is responsive, closing it\n',
    '2021-06-16T01:08:32.409Z workers Merging parallel test run results\n',
    '2021-06-16T01:08:32.409Z project Test run finished\n',
    '2021-06-16T01:08:32.410Z project Processed console.log entries\n',
    '2021-06-16T01:08:32.410Z project Processed loading sequences\n',
    '2021-06-16T01:08:32.410Z project Processed executed tests\n',
    '2021-06-16T01:08:32.414Z project Processed code coverage\n',
    '2021-06-16T01:08:32.453Z project Test run result processed and sent to IDE\n'
  ]
}

lerna.json

{
  "$schema": "https://json.schemastore.org/lerna.json",
  "version": "independent",
  "npmClient": "yarn",
  "useWorkspaces": true,
  "command": {
    "publish": {
      "ignoreChanges": [
        "*.config.js",
        ".eslint.js",
        "*.md",
        "*.yml",
        "*.yaml",
        "**/tests/**",
        "**/integration/**",
        "**/__tests__/**",
        "**/__mocks__/**"
      ],
      "conventionalCommits": true,
      "message": "chore(release): publish",
      "yes": false,
      "registry": "https://localhost:4157",
      "allowBranch": ["release/*", "hotfix/*", "feature/*"]
    },
    "version": {
      "ignoreChanges": [
        "*.config.js",
        ".eslint.js",
        "*.md",
        "*.yml",
        "*.yaml",
        "**/tests/**",
        "**/integration/**",
        "**/__tests__/**",
        "**/__mocks__/**"
      ],
      "message": "chore(release): version",
      "conventionalCommits": true,
      "changelogPreset": "./changelog-preset.config.js",
      "yes": true,
      "allowBranch": ["release/*", "hotfix/*", "feature/*"]
    }
  }
}

the project structure is as follows:

api-project-yarn
   /packages
       /npm-scripts
            /lib
            /tests
                /unit
            package.json
            jest.config.js
            tsconfig.json
            tsconfig.build.json
       /core-sdk
            /lib
            /tests
                /unit
            package.json
            jest.config.js
            tsconfig.json
            tsconfig.build.json
       /logging-sdk
            /lib
            /tests
                /unit
            package.json
            jest.config.js
            tsconfig.json
            tsconfig.build.json
       /testing
            /lib
            /tests
                /unit
            package.json
            jest.config.js
            tsconfig.json
            tsconfig.build.json
       /utils-sdk
            /lib
            /tests
                /unit
            package.json
            jest.config.js
            tsconfig.json
            tsconfig.build.json
       /http-client-sdk
            /lib
            /tests
                /unit
            package.json
            jest.config.js
            tsconfig.json
            tsconfig.build.json

each packages/**package.json is for scripts and *dependencies:

{
  "scripts": {
       "test": "jest --detectOpenHandles"
  },
  "main": "dist/lib/index.js",
  "types": "dist/lib/index.d.ts",
  "directories": {
    "dist": "dist",
    "lib": "lib",
    "test": "tests"
  },
  "peerDependenciesMeta": {
    "@company/http-client-sdk": {
      "optional": false
    },
    "@company/logging-sdk": {
      "optional": false
    },
    "@company/utils-sdk": {
      "optional": false
    }
  },
  "peerDependencies": {
    "@company/http-client-sdk": "^1.7.0",
    "@company/logging-sdk": "^1.7.0",
    "@company/utils-sdk": "^1.7.0"
  },
  "devDependencies": {
    "@company/http-client-sdk": "1.9.0-feature-tro-1836-docs.2",
    "@company/logging-sdk": "1.9.0-feature-tro-1836-docs.2",
    "@company/testing": "1.9.0-feature-tro-1836-docs.2",
    "@company/utils-sdk": "1.9.0-feature-tro-1836-docs.2",
    "@types/jest": "^26.0.23",
    "@typescript-eslint/eslint-plugin": "^4.26.1",
    "@typescript-eslint/parser": "^4.26.1",
    "eslint": "^7.28.0",
    "jest": "^27.0.4",
    "lint-staged": "^11.0.0",
    "rimraf": "^3.0.2",
    "ts-jest": "^27.0.3",
    "typedoc": "^0.20.36",
    "typedoc-plugin-markdown": "^3.9.0",
    "typescript": "^4.3.2"
  }
}

each packages/**/jest.config.js the same:

const { pathsToModuleNameMapper } = require('ts-jest/utils');
// Load the config which holds the path aliases.
const { compilerOptions } = require('../../tsconfig.json');

const packageFile = require('./package.json');

module.exports = {
  displayName: packageFile.name,
  preset: '../../jest.unit.preset.js',
  globals: {
    'ts-jest': {
      tsconfig: '<rootDir>/tsconfig.json'
    }
  },
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
    // This has to match the baseUrl defined in tsconfig.json.
    prefix: '<rootDir>/../../'
  }),
  coverageDirectory: `../../coverage/packages/${packageFile.name}`
};

each packages/**/tsconfig.build.json is the same:

{
  "extends": "../../tsconfig.build.json",

  "compilerOptions": {
    "outDir": "./dist"
  },

  "include": ["lib/**/*"]
}

each packages/**/tsconfig.json is similar (this one is for core-sdk):

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "types": ["jest", "node"]
  },
  "references": [
    {
      "path": "../logging-sdk"
    },
    {
      "path": "../http-client-sdk"
    },
    {
      "path": "../testing"
    }
  ]
}

The key difference in each one is the references area

<root>/jest.unit.preset.js

module.exports = {
  testEnvironment: 'node',
  moduleFileExtensions: ['js', 'ts'],
  globals: {
    'ts-jest': {
      tsconfig: '<rootDir>/tsconfig.json'
    }
  },
  testMatch: ['**/unit/**/?(*.)+(spec|test).[jt]s?(x)'],
  transform: {
    '^.+\\.(ts)$': 'ts-jest'
  },
  verbose: false,
  silent: true,
  coverageReporters: ['lcov', 'text'],
  coverageThreshold: {
    global: {
      branches: 90,
      functions: 90,
      lines: 90,
      statements: 90
    }
  }
};

<root>/tsconfig.json

{
  "extends": "./tsconfig.build.json",
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@company/*": ["packages/*/lib"]
    }
  }
}

<root>/tsconfig.build.json

{
  "$schema": "http://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "allowJs": false,
    "declaration": true,
    "sourceMap": false,
    "composite": true,
    "removeComments": false,
    "noEmitOnError": true,
    "strict": true,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "typeRoots": ["node_modules/@types"],
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "noLib": false,
    "allowUnreachableCode": false,
    "resolveJsonModule": true
  }
}
@smcenlly
Copy link
Member

Are you able to share a sample repo of your project structure/setup? We need to know about your project structure, jest setup, etc. in order to try work out what's going on.

@kvernon
Copy link
Author

kvernon commented Jun 16, 2021

Thank you as always for helping @smcenlly !

I don't have a way to share the project (it's work), but I can probably provide more setup/config files.

Would that help?

(This yarn adaptation has been war)

@smcenlly
Copy link
Member

Yes, please provide all the configuration files (tsconfig.json, lerna.json, jest.config.js, etc.) and provide an example of the structure.

@kvernon
Copy link
Author

kvernon commented Jun 16, 2021

@smcenlly I've updated all that I can think of within the original comment above.

I've added the project layout
tsconfig.*.json files
jest.config.js files
package.json

And I just "pretty up" the pieces above...

@smcenlly
Copy link
Member

@kvernon - we're not especially familiar with yarn2 and lerna running together and haven't been able to get it to work for us.

We kept getting:

lerna ERR! yarn install --mutex network:42424 --non-interactive exited 1

as mentioned here: lerna/lerna#2449


Instead, we set up a similar yarn2 project that had almost the same configuration but everything was working for us.


Could you please:

  1. Reproduce your issue in a sample repo (without any of your project code) with the minimal configuration that you provided above and a code sample that has the same issue.
  2. Provide steps for setting up the repo from scratch.
  3. Provide steps for running the tests from the CLI.

@kvernon
Copy link
Author

kvernon commented Jun 16, 2021

@smcenlly

ya, I'm new with it too. You actually run yarn install instead of lerna bootstrap

Also, I'll see what I can do. It'll take a few days. They just the me on a last minute project

Also, you should be able to run lerna add <package>

@kvernon
Copy link
Author

kvernon commented Jun 17, 2021

Howdy @smcenlly I was able to put this together: https://github.com/kvernon/wallaby-lerna4-yarn2/tree/master

P.S. I screwed up using github, and made a master branch not related to main, so if you get lost look for master.

also directions are on the master readme.

@smcenlly
Copy link
Member

smcenlly commented Jun 17, 2021

@kvernon - thanks for providing the sample repo. I wasn't expecting to see node_modules directory but I can see that it's there with your configuration.

Can you see if this configuration is working for you?

wallaby.js

module.exports = () => ({
  autoDetect: true,
  files: [
    '!**/packages/tests/integration/**/*',
    { pattern: 'node_modules/@company/**', ignore: true }
  ],
  tests: [
    '**/tests/unit/**/*.test.*',
    { pattern: 'node_modules/@company/**', ignore: true }
  ],
  testFramework: {
    // the jest configuration file path
    // (relative to project root)
    configFile: './jest.config.js'
  },
  debug: true
});

We're still not entirely sure why jest is working from the command-line and not from Wallaby so I am still investigating that but the configuration above seems to work for us.

@smcenlly
Copy link
Member

smcenlly commented Jun 17, 2021

It looks like there are still a few other problems; coverage indicators and inline value display isn't working properly. It looks like in the context of Wallaby running (at least, - we're not sure if this also affects jest), Wallaby may be using the code from node_modules instead of the moduleNameMapper configuration.

@smcenlly
Copy link
Member

Thanks again for the sample repo, it really helped diagnose what was going on.

There were two issues:

  1. ts-jest recently made a change in how the TypeScript sourceMap setting is used. It used to always be set to true. It appears that there are now some circumstances (I think tsconfig.json files that extend from another file) where the sourceMap setting is no longer set.

To fix this, you need to update <root>/tsconfig.json:

{
  "extends": "./tsconfig.build.json",
  "compilerOptions": {
+   "sourceMap": true,
    "baseUrl": ".",
    "paths": {
      "@company/*": ["packages/*/lib"]
    },
  }
}
  1. You were overriding the files and test patterns in your wallaby.js configuration file but not providing a complete configuration to load files for your project. This meant that only test files were being loaded and Wallaby ended up resolving the rest of your project files from your node_modules/@company folder, which were not transformed, etc.

There are a few ways you can fix this:

Wallaby.js - provide a complete files/tests configuration:

module.exports = () => ({
  autoDetect: true,

  // provide files[] and tests[] patterns to match all required source/tests for project
  files: [
    'packages/**',
    '!packages/**/tests/**',
  ],
  tests: [
    'packages/**/tests/unit/**/?(*.)+(spec|test).[jt]s?(x)',    
  ],

  testFramework: {
    configFile: './jest.config.js'
  }
});

Wallaby.js - override autoDetect configuration to adjust files/tests:

module.exports = () => ({
  autoDetect: true,

  // override tests to exclude integration tests that run using jest without wallaby
  tests: {
    override: (testPatterns) => {
      testPatterns.push('!**/packages/tests/integration/**/*');
      return testPatterns;
    }
  },
  testFramework: {
    configFile: './jest.config.js'
  }
});

Wallaby.js - override autoDetect configuration to use a different jest.config.js for Wallaby:

module.exports = () => ({
  autoDetect: true,

  // use a separate jest configuration file that extends from base configuration but excludes 
  // additional files (e.g. integration tests)
  testFramework: {
    configFile: './jest.wallaby.config.js'
  }
});

@kvernon
Copy link
Author

kvernon commented Jun 17, 2021

Thank you, @smcenlly, for helping me with this. I'll report later today over how this goes.

I do have one question observation from all of this.
Wallaby has a tests area, jest has a testmatch in their config, is there anyway wallaby could use that more? With the example of this repo, I've had test/unit and test/integration, and the jest.config.js is explicit about it only running tests within the unit folders. Wallabjs however, runs tests in unit and integration. It would be wonderful if the autoconfig option could pick that up as well

@kvernon
Copy link
Author

kvernon commented Jun 17, 2021

@smcenlly I applied the changes to repo -- they work for that issue.

For the next part tho, yea, but this should be the last part. I have issues with coverage

When you pull latest, you'll see I added coverage that restricts files. I added notes to the readme as well.

The problem is this. We have to restrict coverage in jest, when I apply this with jest, it works, however, wallabjs is dead in the water when I tell it to avoid files.

jest.unit.preset has this addition

  collectCoverageFrom: [
    '!**/tests/integration/**',
    '!**/**/.eslintrc.js',
    '!**/**/jest.config.js',
    '!**/**/jest.integration.config.js',
  ]

pretty common stuff to not include for test coverage. How do I get wallabjs to work with this information applied?

from the branch, when you run yarn run test:cov you'll see that it is able to show coverage, while when you run this and check the IDE and wallabyjs localhost (browser), it cannot do any coverage over the files (and actually errors claiming a connection issue)

@kvernon
Copy link
Author

kvernon commented Jun 17, 2021

Also, I was reviewing this again (before the branch update I did), and I noticed that the coverage was not updated with it as well. Like the tests passed, and there were boxes on the tests, but the file doesn't have boxes (red/green/gray) indicating coverage.

@smcenlly smcenlly reopened this Jun 17, 2021
@smcenlly
Copy link
Member

How do I get wallabjs to work with this information applied?

If you set the collectCoverageFrom setting, Wallaby needs you to provide the list of patterns to match. In the repo you provided, this should work for you:

jest.unit.preset.js

...
  collectCoverageFrom: [
+   '**/*.ts',
    '!**/tests/integration/**',
    '!**/**/.eslintrc.js',
    '!**/**/jest.config.js',
    '!**/**/jest.integration.config.js',
  ],
...

I do have one question observation from all of this.
Wallaby has a tests area, jest has a testmatch in their config, is there anyway wallaby could use that more? With the example of this repo, I've had test/unit and test/integration, and the jest.config.js is explicit about it only running tests within the unit folders. Wallabjs however, runs tests in unit and integration. It would be wonderful if the autoconfig option could pick that up as well

This may be a bug in Wallaby; we'll do some investigation and let you know.

@smcenlly
Copy link
Member

Wallaby has a tests area, jest has a testmatch in their config, is there anyway wallaby could use that more? With the example of this repo, I've had test/unit and test/integration, and the jest.config.js is explicit about it only running tests within the unit folders. Wallabjs however, runs tests in unit and integration. It would be wonderful if the autoconfig option could pick that up as well

I just tested this in your sample repo and Wallaby does not run tests in the integration folder. Can you reproduce this problem?

@kvernon
Copy link
Author

kvernon commented Jun 21, 2021

Howdy @smcenlly,

When I add '**/*.ts', I still do not see coverage show up the Core file

Note: I've updated the master branch

@smcenlly
Copy link
Member

I reviewed your repo and it seems that you updated <root>/tsconfig.build.json instead of:

To fix this, you need to update <root>/tsconfig.json

I have sent you a pull request for your repo with everything working (also available in our fork of your repo).

@kvernon
Copy link
Author

kvernon commented Jun 22, 2021

@smcenlly thank you for looking at this.

TL;DR

I applied the change and it works.

Longer:

So, I honestly don't know how to go forward. This change works, but this exact same setup applied fails

I've done:

  1. the wallabjs config bare-bones like you have
  2. ensured the tsconfig has sourceMap : true
  3. ensured the jest.config.js only points to unit tests

Result on my actual project:

I get integration tests that attempt run that are outside of the jest.config project scope

@kvernon
Copy link
Author

kvernon commented Jun 22, 2021

@smcenlly OK, I think I've got the issue around why the autoconfig could easily happen:

https://github.com/kvernon/wallaby-lerna4-yarn2/tree/feature/exclusion

in this:

  • jest.config only references core-sdk
  • tests added for http-client

Results

  1. core-sdk have their unit tests run.
  2. http-client-sdk have their unit tests run. (which should not)

Wallaby Console:

wallaby.js started
core v1.0.1097
console.log: Jest: PASS @company/core-sdk packages/http-client-sdk/tests/unit/client.test.ts

console.log: Jest: PASS @company/core-sdk packages/core-sdk/tests/unit/core.test.ts

Finished executing 2 affected test(s) in 2.44 second(s)

Note: I still cannot get it to show int tests running in this example

@kvernon
Copy link
Author

kvernon commented Jun 22, 2021

Ooooh, @smcenlly , I think I may know what's going on with the integration tests.

So in the wallabyjs (same simple config you supplied), we ignore the integration tests, however they still load, which leaves the idea of doing something like:

example 1:

module.exports = () => ({
  autoDetect: true,
  files: [
    '!packages/*/tests/integration/**/*.ts'
  ],
  debug: true,
  trace: true
});

example 2:

module.exports = () => ({
  autoDetect: true,
  files: [
    { pattern: 'packages/*/tests/integration/*.ts', hideFromErrorStackTrace: true, instrument: false, load: false },
    { pattern: 'packages/*/tests/integration/**/*.ts', hideFromErrorStackTrace: true, instrument: false, load: false }
  ],
  debug: true,
  trace: true
})

However every time I try to get it to NOT load those files, I still see the same error of:

Note: updating the logging info below to hide actual names

./packages/actual-library-sdk/tests/integration/session.middleware.test.ts: Unexpected token, expected "," (53:50)

  51 |  * @param cookie
  52 |  */
> 53 | function doSession(server, cookie: string) {
     |                                                   ^
  54 |   return request(server)
  55 |     .get('/validatesession')
  56 |     .set('Cookie', `tos_token=${cookie}`);

So, I got questions!

  1. do I have the right idea over this; meaning it's trying to read files I don't care about?
  2. how do I block all tests/integration within and packages/{library-folder}/ ?

and thank you and your team with all your help on this again!

@smcenlly
Copy link
Member

Thanks for updating the sample repo with the new branch. We can see what this is happening now. We had understood from your previous message that each packages/**/jest.config.js is the same but this is not the case in your latest branch, and is the cause of your problem.

Unlike Jest, when Wallaby runs your jest tests, Wallaby merges your various jest configurations and runs on all jest projects together at the same time. There are a few things that matter with Wallaby that don't matter so much with Jest (certainly not with lerna):

a. Dependencies should be the same version (or you may run into some weird issues).
b. Different testMatch patterns across multiple jest configurations are unioned with each other, which means that wildcard test match patterns will match any project, not just their own.

(b) is causing a problem in your case.

Your testMatch pattern for core-sdk is:

  testMatch: ['**/unit/**/?(*.)+(spec|test).[jt]s?(x)'],

But your testMatch pattern for npm-scripts is:

  testMatch: ['**/tests/**/?(*.)+(spec|test).[jt]s?(x)'],

When Wallaby unions the testMatch patterns, it tries to find tests for all projects based on:

  testMatch: [
    '**/unit/**/?(*.)+(spec|test).[jt]s?(x)',      // or
    '**/tests/**/?(*.)+(spec|test).[jt]s?(x)'
],

When the testMatch patterns are merged, the npm-scripts pattern is not specific enough for the npm-scripts project and so Wallaby runs on all projects and is incorrectly selecting the tests for core-sdk. Arguably, Wallaby wouldn't do this and would have the same behavior as Jest CLI, but we may not be able to change this behavior since we are running all tests for your projects together which is something foreign to Jest.


There are a couple of ways you can fix this:

1. Ensure testMatch patterns are consistent across all projects.

2. Ensure testMatch patterns that are overridden have enough context to specify project name, for example (packages\npm-scripts\jest.config.js):

const packageFile = require('./package.json');
const preset = require('../../jest.unit.preset');

delete preset.testMatch;
delete preset.globals;
delete preset.transform;
delete preset.coverageThreshold;

module.exports = {
  ...preset,
  testMatch: ['**/npm-scripts/tests/**/?(*.)+(spec|test).[jt]s?(x)'],
  displayName: packageFile.name,
  coverageDirectory: `../../coverage/packages/${packageFile.name}`
};

3. Override with a Wallaby configuration file to exclude integration tests for all projects (wallaby.js):

module.exports = () => ({
  autoDetect: true,

  // override tests to exclude integration tests that run using jest without wallaby
  tests: {
    override: (testPatterns) => {
      testPatterns.push('!packages/**/tests/integration/**/?(*.)+(spec|test).[jt]s?(x)');
      return testPatterns;
    }
  },
  testFramework: {
    configFile: './jest.config.js'
  }
});

Please make sure that you only apply one of the fixes as applying multiple at the same time, may cause other test selection problems.


Regarding your questions:

do I have the right idea over this; meaning it's trying to read files I don't care about?

Since you have overridden the files section of the configuration, you have not provided a full configuration of files that Wallaby/Jest need to transform and process, which is why it's not working for you. If you set the files array, you need to provide a full configuration of project files that Wallaby should process (includes and excludes, for both application files and test files). Alternatively, you may use the override function as shown in (3) above, and as per our previous reply.

how do I block all tests/integration within and packages/{library-folder}/ ?

See the example in (3) above. You can add additional patterns to be project specific if you need (instead of using the packages/** wildcard).

@kvernon
Copy link
Author

kvernon commented Jun 23, 2021

Thank you again, @smcenlly.

I did the test object override, and it looks like it did the job.

I suppose the only thing that really comes from this is documenting the overrides for tests? I went here, https://wallabyjs.com/docs/config/files.html and there is no information on how to override and when to array vs object for tests.

Again, this is great! thank you and your team again with your time in helping me.

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

2 participants