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

Directly linking typescript files without compilation breaks with wallabyjs #2909

Closed
bhvngt opened this issue Jan 19, 2022 · 1 comment
Closed

Comments

@bhvngt
Copy link

bhvngt commented Jan 19, 2022

Issue description or question

Based on following this blog, I was trying to directly link my internal packages by changing the package.json exports as follows and removing the build step.

  "exports": {
    "./*": "./src/*.ts" // instead of "./dist/*.js"
  },
  "typesVersions": {
    "*": {
      "*": ["./src/*"] // instead of "./dist/*"
    }
  },

I am able to run my mocha test suite on the cli without any issue. My mocha config file is as follows

module.exports = {
	"node-option": [
		"experimental-specifier-resolution=node",
		"loader=esbuild-node-loader" // works with ts-node/esm also. I prefer esbuild-node-loader since it has built-in support for path alias.
	],
	"require": ["dotenv/config", "./tests/helpers/globalSetup.js", "chai/register-should"],
};

However, when I run the same test in wallaby, it throws following error.

Runtime error: TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "file://./libs/store/src/SupabaseConnection.ts" 
    at new NodeError (node:internal/errors:371:5)
    at ESMLoader.load (node:internal/modules/esm/loader:324:13)
    at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:230:47)

This error disappears if I reintroduce typescript compilation step for internal packages.

Direct linking simplifies my development time significantly as I can completely skip build time for internal packages. Any help here will be very much appreciated.

Wallaby diagnostics report

{
  editorVersion: 'IntelliJ IDEA 2021.3.2 Preview',
  pluginVersion: '1.0.231',
  editorType: 'IntelliJ',
  osVersion: 'darwin 21.2.0',
  nodeVersion: 'v16.13.1',
  coreVersion: '1.0.1209',
  checksum: 'MmUxNzQ4YTIxNGUwZjZhODg5YWRhNzc5Y2E0OWY3MzgsMTY2OTU5MzYwMDAwMCww',
  config: {
    files: [
      { pattern: 'package.json', ignore: false, trigger: true, load: true, instrument: true, order: 1 },
      { pattern: '**/{src,tests,types}/**/!(*.+(test|spec)).{js,ts}', ignore: false, trigger: true, load: true, instrument: true, order: 2 },
      { pattern: '{temp,apps,tools,utils}/**/*', ignore: true, trigger: true, load: true, instrument: true },
      { pattern: 'libs/ui/**/*', ignore: true, trigger: true, load: true, instrument: true },
      { pattern: '**/node_modules/**', ignore: true, trigger: true, load: true, instrument: true },
      { pattern: '.env', instrument: false, ignore: false, trigger: true, load: true, order: 3 }
    ],
    tests: [
      { pattern: '**/tests/**/*.+(test|spec).ts', ignore: false, trigger: true, load: true, test: true, order: 4 },
      { pattern: '{temp,apps,tools,utils}/**/*', ignore: true, trigger: true, load: true, test: true },
      { pattern: 'libs/ui/**/*', ignore: true, trigger: true, load: true, test: true },
      { pattern: '**/node_modules/**', ignore: true, trigger: true, load: true, test: true }
    ],
    testFramework: { version: 'mocha@2.1.0', configurator: 'mocha@2.1.0', reporter: 'mocha@2.1.0', starter: 'mocha@2.1.0' },
    filesWithNoCoverageCalculated: [ '**/node_modules/**', '**/tests/**/*.+(test|spec).{js,ts}' ],
    env: {
      type: 'node',
      params: { runner: '--experimental-specifier-resolution=node' },
      DOTENV_CONFIG_PATH: '.env',
      runner: '<homeDir>/.fnm/node-versions/v16.13.1/installation/bin/node',
      viewportSize: { width: 800, height: 600 },
      options: { width: 800, height: 600 },
      bundle: true
    },
    workers: { restart: true, initial: 0, regular: 0, recycle: true },
    debug: true,
    reportConsoleErrorAsError: true,
    diagnostics: {},
    runAllTestsInAffectedTestFile: false,
    updateNoMoreThanOneSnapshotPerTestFileRun: false,
    addModifiedTestFileToExclusiveTestRun: true,
    compilers: { '**/*.?(lit)coffee?(.md)': [Function (anonymous)] },
    preprocessors: {},
    maxConsoleMessagesPerTest: 100,
    autoConsoleLog: true,
    delays: { run: 0, edit: 100, update: 0 },
    teardown: undefined,
    hints: {
      ignoreCoverage: '__REGEXP /ignore coverage|istanbul ignore/',
      ignoreCoverageForFile: '__REGEXP /ignore file coverage/',
      commentAutoLog: '?',
      testFileSelection: { include: '__REGEXP /file\\.only/', exclude: '__REGEXP /file\\.skip/' }
    },
    automaticTestFileSelection: true,
    runSelectedTestsOnly: false,
    mapConsoleMessagesStackTrace: false,
    extensions: {},
    reportUnhandledPromises: true,
    slowTestThreshold: 75,
    lowCoverageThreshold: 80,
    loose: undefined,
    symlinkNodeModules: true,
    configCode: 'const filterCategories = ["temp", "apps", "tools", "utils"].join(",");\n' +
      'global._ranSetup = false;\n' +
      'module.exports = function(wallaby) {\n' +
      '\treturn {\n' +
      '\t\tfiles: [\n' +
      '\t\t\t"package.json",\n' +
      '\t\t\t"**/{src,tests,types}/**/!(*.+(test|spec)).{js,ts}",\n' +
      '\t\t\t`!{${filterCategories}}/**/*`,\n' +
      '\t\t\t"!libs/ui/**/*",\n' +
      '\t\t\t"!**/node_modules/**",\n' +
      '\t\t\t{\n' +
      '\t\t\t\tpattern: ".env",\n' +
      '\t\t\t\tinstrument: false\n' +
      '\t\t\t}\n' +
      '\t\t],\n' +
      '\n' +
      '\t\ttests: [\n' +
      '\t\t\t"**/tests/**/*.+(test|spec).ts",\n' +
      '\t\t\t`!{${filterCategories}}/**/*`,\n' +
      '\t\t\t"!libs/ui/**/*",\n' +
      '\t\t\t"!**/node_modules/**"\n' +
      '\t\t],\n' +
      '\n' +
      '\t\ttestFramework: "mocha",\n' +
      '\t\tfilesWithNoCoverageCalculated: ["**/node_modules/**", "**/tests/**/*.+(test|spec).{js,ts}"],\n' +
      '\n' +
      '\t\tenv: {\n' +
      '\t\t\ttype: "node",\n' +
      '\t\t\tparams: {\n' +
      '\t\t\t\trunner: "--experimental-specifier-resolution=node"\n' +
      '\t\t\t},\n' +
      '\t\t\t"DOTENV_CONFIG_PATH": ".env"\n' +
      '\t\t},\n' +
      '\n' +
      '\t\tworkers: { restart: true },\n' +
      '\t\tdebug: true,\n' +
      '\t\treportConsoleErrorAsError: true,\n' +
      '\t\tsetup: async (wallaby) => {\n' +
      '\t\t\tif (!global._ranSetup) {\n' +
      '\t\t\t\t// global._ranSetup = true;\n' +
      '\t\t\t\trequire("dotenv/config");\n' +
      "\t\t\t\trequire('chai').should();\n" +
      '\t\t\t\t// const path = require("path");\n' +
      '\t\t\t\t// const libStoreSetup = await import(path.join(wallaby.localProjectDir, "libs/store/tests/helpers/setupSignupUser.js"));\n' +
      '\t\t\t\t// const libServiceSetup = await import(path.join(wallaby.localProjectDir, "libs/service/tests/helpers/setupSignupUser.js"));\n' +
      '\t\t\t\t// await libStoreSetup.mochaGlobalSetup();\n' +
      '\t\t\t\t// await libServiceSetup.mochaGlobalSetup();\n' +
      '\t\t\t\tconst fs = require("fs");\n' +
      '\t\t\t\tconst json5 = require("json5");\n' +
      '\t\t\t\tconst rushJson = json5.parse(fs.readFileSync(`${wallaby.localProjectDir}/rush.json`, "utf-8"));\n' +
      '\t\t\t\tconsole.log("Sym linking rush modules");\n' +
      '\t\t\t\trushJson.projects.map(project => {\n' +
      '\t\t\t\t\tconst [packageCategory, packageName] = project.packageName.split("/");\n' +
      '\t\t\t\t\tconst categoryDir = `./node_modules/${packageCategory}`;\n' +
      '\t\t\t\t\tif (!fs.existsSync(categoryDir)) fs.mkdirSync(categoryDir);\n' +
      '\t\t\t\t\tif (!fs.existsSync(`${categoryDir}/${packageName}`)) {\n' +
      '\t\t\t\t\t\tconsole.log("Sym linking", project.packageName);\n' +
      '\t\t\t\t\t\tconst sourcePath = `${wallaby.localProjectDir}/${project.projectFolder}`;\n' +
      '\t\t\t\t\t\tconst targetPath = `${categoryDir}/${packageName}`;\n' +
      '\t\t\t\t\t\tconsole.log(`Sym linking ${sourcePath} with ${targetPath}`);\n' +
      '\t\t\t\t\t\tfs.symlinkSync(sourcePath, targetPath);\n' +
      '\t\t\t\t\t}\n' +
      '\t\t\t\t});\n' +
      '\t\t\t}\n' +
      '\t\t}\n' +
      '\t};\n' +
      '};\n'
  },
  packageJSON: { dependencies: undefined, devDependencies: undefined },
  fs: { numberOfFiles: 33 },
  debug: [
    '2022-01-19T11:14:13.134Z project Wallaby Node version: v16.13.1\n',
    '2022-01-19T11:14:13.135Z project Wallaby config: <homeDir>/Projects/lab/innerview/wallaby.cjs\n',
    '2022-01-19T11:14:23.620Z fs File system scan has finished by timeout\n',
    '2022-01-19T11:14:23.633Z project File cache: <homeDir>/Library/Caches/JetBrains/IntelliJIdea2021.3/wallaby/projects/57e7e640d3458563\n',
    '2022-01-19T11:14:23.781Z uiService Listening port 51235\n',
    '2022-01-19T11:14:24.102Z workers Parallelism for initial run: 2, for regular run: 2\n',
    '2022-01-19T11:14:24.102Z workers Starting run worker instance #0\n',
    '2022-01-19T11:14:24.103Z workers Starting run worker instance #1\n',
    '2022-01-19T11:14:24.105Z workers Web server is listening at 52499\n',
    '2022-01-19T11:14:24.721Z project Stopping process pool\n',
    '2022-01-19T11:14:24.721Z project File cache is up-to-date, starting full test run\n',
    '2022-01-19T11:14:24.791Z project Running postprocessor\n',
    '2022-01-19T11:14:24.797Z postprocessor New TypeScript language service is required\n',
    '2022-01-19T11:14:26.318Z workers Started run worker instance (delayed) #1\n',
    '2022-01-19T11:14:26.318Z workers Started run worker instance (delayed) #0\n',
    '2022-01-19T11:14:26.367Z project Postprocessor execution finished\n',
    '2022-01-19T11:14:26.367Z project Test run started; run priority: 3\n',
    '2022-01-19T11:14:26.368Z project Running all tests\n',
    '2022-01-19T11:14:26.371Z workers Starting test run, priority: 3\n',
    '2022-01-19T11:14:26.371Z workers Distributing tests between 2 workers\n',
    '2022-01-19T11:14:26.371Z workers Running tests in parallel\n',
    '2022-01-19T11:14:26.372Z nodeRunner Starting sandbox [worker #0, session #s2e1w]\n',
    '2022-01-19T11:14:26.372Z nodeRunner Starting sandbox [worker #1, session #ae708]\n',
    '2022-01-19T11:14:26.372Z nodeRunner Preparing sandbox [worker #0, session #s2e1w]\n',
    '2022-01-19T11:14:26.372Z nodeRunner Preparing sandbox [worker #1, session #ae708]\n',
    '2022-01-19T11:14:26.372Z nodeRunner Prepared sandbox [worker #0, session #s2e1w]\n',
    '2022-01-19T11:14:26.372Z nodeRunner Prepared sandbox [worker #1, session #ae708]\n',
    '2022-01-19T11:14:26.373Z workers [worker #0, session #s2e1w] Running tests in sandbox\n',
    '2022-01-19T11:14:26.373Z workers [worker #1, session #ae708] Running tests in sandbox\n',
    '2022-01-19T11:14:27.540Z workers Sandbox (active) [s2e1w] error: Invalid module "file://<homeDir>/Projects/lab/innerview/libs/store/src/SupabaseConnection.ts" \n',
    '2022-01-19T11:14:27.541Z workers Failed to map the stack to user code, entry message: Invalid module "file://<homeDir>/Projects/lab/innerview/libs/store/src/SupabaseConnection.ts" , stack: TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "file://<homeDir>/Projects/lab/innerview/libs/store/src/SupabaseConnection.ts" \n' +
      '    at new NodeError (node:internal/errors:371:5)\n' +
      '    at ESMLoader.load (node:internal/modules/esm/loader:324:13)\n' +
      '    at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:230:47)\n',
    '2022-01-19T11:14:27.586Z workers Sandbox (active) [ae708] error: Invalid module "file://<homeDir>/Projects/lab/innerview/libs/store/src/SupabaseConnection.ts" \n',
    '2022-01-19T11:14:27.586Z workers Failed to map the stack to user code, entry message: Invalid module "file://<homeDir>/Projects/lab/innerview/libs/store/src/SupabaseConnection.ts" , stack: TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "file://<homeDir>/Projects/lab/innerview/libs/store/src/SupabaseConnection.ts" \n' +
      '    at new NodeError (node:internal/errors:371:5)\n' +
      '    at ESMLoader.load (node:internal/modules/esm/loader:324:13)\n' +
      '    at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:230:47)\n',
    '2022-01-19T11:14:27.641Z workers [s2e1w] Run 0 test(s), skipped 0 test(s)\n',
    '2022-01-19T11:14:27.721Z workers [ae708] Run 0 test(s), skipped 0 test(s)\n',
    '2022-01-19T11:14:27.907Z workers [s2e1w] Sandbox is responsive, closing it\n',
    '2022-01-19T11:14:27.908Z workers Starting run worker instance #0\n',
    '2022-01-19T11:14:28.191Z workers [ae708] Sandbox is responsive, closing it\n',
    '2022-01-19T11:14:28.191Z workers Starting run worker instance #1\n',
    '2022-01-19T11:14:28.192Z workers Merging parallel test run results\n',
    '2022-01-19T11:14:28.193Z project Test run finished\n',
    '2022-01-19T11:14:28.194Z project Processed console.log entries\n',
    '2022-01-19T11:14:28.194Z project Processed loading sequences\n',
    '2022-01-19T11:14:28.194Z project Processed executed tests\n',
    '2022-01-19T11:14:28.223Z project Processed code coverage\n',
    '2022-01-19T11:14:28.271Z project Test run result processed and sent to IDE\n',
    '2022-01-19T11:14:28.960Z workers Started run worker instance (delayed) #0\n',
    '2022-01-19T11:14:29.041Z workers Started run worker instance (delayed) #1\n'
  ]
}
@ArtemGovorov
Copy link
Member

Can you please create a sample project repo with the working mocha setup (as you want it to work ideally) and we'll take a look to see how to configure the same thing in Wallaby? If you like, you may combine the sample repo with the other issue you've raised #2910.

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

No branches or pull requests

3 participants