wallabyjs / public

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

How to load "exernal" scripts via script tags <script ... > #2760

Closed tomitrescak closed 3 years ago

tomitrescak commented 3 years ago

Issue description or question

Hi, I'm trying to run tests where I need to load some global scripts (not require), but I'm failing. I tried via node.js and jsdom but it did not work. I tried with pure browser exaplme from 'https://github.com/wallabyjs/wallaby-typescript-sample/' but again no luck.

When I run my simple test:

import expect from 'expect';

it('loads brython', function () {
  expect(window.$B).toBeDefined();
});

I get this error:

TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../". 

My secon question would be: how can I include scripts that are loaded in the page, such as <script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.5/brython.min.js"></script>

Tank you!

Wallaby diagnostics report

{
  editorVersion: '1.58.2',
  pluginVersion: '1.0.300',
  editorType: 'VSCode',
  osVersion: 'win32 10.0.19041',
  nodeVersion: 'v14.16.1',
  coreVersion: '1.0.1117',
  checksum: 'NjkzYWE3YWU0NTRjODYwOWZkYzAwMTBjMjdiNmIxOTIsMTYzODkyMTYwMDAwMCww',
  config: {
    files: [ { pattern: 'src/compilers/python/**/*.ts', ignore: false, trigger: true, load: true, instrument: true, order: 1 } ],
    tests: [ { pattern: 'test/compilers/python/**/*.test.ts', ignore: false, trigger: true, load: true, test: true, order: 2 } ],
    diagnostics: {},
    filesWithNoCoverageCalculated: [],
    runAllTestsInAffectedTestFile: false,
    updateNoMoreThanOneSnapshotPerTestFileRun: false,
    addModifiedTestFileToExclusiveTestRun: true,
    compilers: { '**/*.?(lit)coffee?(.md)': [Function (anonymous)] },
    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: 'browser', kind: 'chrome', params: {}, viewportSize: { width: 800, height: 600 }, options: { width: 800, height: 600 }, bundle: true },
    reportUnhandledPromises: false,
    throwOnBeforeUnload: true,
    testFramework: { version: 'jasmine@3.6.0', configurator: 'jasmine@2.1.3', reporter: 'jasmine@2.1.3', starter: 'jasmine@2.1.3' },
    slowTestThreshold: 75,
    lowCoverageThreshold: 80,
    loose: undefined,
    configCode: '// @ts-nocheck1\r\n' +
      '// eslint-disable-next-line @typescript-eslint/no-var-requires\r\n' +
      'module.exports = function (wallaby) {\r\n' +
      '  return {\r\n' +
      "    files: ['src/compilers/python/**/*.ts'],\r\n" +
      '\r\n' +
      "    tests: ['test/compilers/python/**/*.test.ts']\r\n" +
      '  };\r\n' +
      '  // return {\r\n' +
      '  //   files: [\r\n' +
      '  //     // {\r\n' +
      "  //     //   pattern: 'src/compilers/java/lib/extendExpect.ts',\r\n" +
      '  //     //   instrument: true,\r\n' +
      '  //     //   hideFromErrorStackTrace: true\r\n' +
      '  //     // },\r\n' +
      "  //     'tsconfig.json',\r\n" +
      "  //     'src/compilers/python/**/*.ts',\r\n" +
      "  //     'src/compilers/*.ts',\r\n" +
      "  //     { pattern: 'public/brython/brython.js', instrument: false },\r\n" +
      "  //     { pattern: 'public/brython/brython_stdlib.js', instrument: false },\r\n" +
      "  //     '!src/compilers/python/**/*.test.ts'\r\n" +
      '  //   ],\r\n' +
      "  //   tests: ['src/compilers/python/**/*.test.ts'],\r\n" +
      '  //   compilers: {\r\n' +
      "  //     '**/*.ts?(x)': wallaby.compilers.typeScript({ module: 'amd' })\r\n" +
      '  //   },\r\n' +
      '  //   env: {\r\n' +
      "  //     type: 'browser',\r\n" +
      "  //     NODE_ENV: 'test'\r\n" +
      '  //   },\r\n' +
      "  //   testFramework: 'mocha',\r\n" +
      '  //   setup() {\r\n' +
      '  //     const mocha = wallaby.testFramework;\r\n' +
      '\r\n' +
      '  //     // if (!global.document) {\r\n' +
      '  //     //   // eslint-disable-next-line @typescript-eslint/no-var-requires\r\n' +
      "  //     //   const jsdom = require('jsdom');\r\n" +
      '  //     //   const { JSDOM } = jsdom;\r\n' +
      '  //     //   global.jsdom = new JSDOM(\r\n' +
      '  //     //     `<!-- index.html -->\r\n' +
      '  //     //   <!DOCTYPE html>\r\n' +
      '  //     //   <html>\r\n' +
      '  //     //     <head>\r\n' +
      '  //     //       <meta charset="utf-8">\r\n' +
      '  //     //       <title>JSDOM test</title>\r\n' +
      '  //     //       <script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.5/brython.min.js"></script>\r\n' +
      '  //     //       <script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.5/brython_stdlib.min.js"></script>\r\n' +
      '  //     //     </head>\r\n' +
      '  //     //     <body>\r\n' +
      '  //     //     </body>\r\n' +
      '  //     //   </html>`,\r\n' +
      '  //     //     {\r\n' +
      "  //     //       url: 'http://localhost',\r\n" +
      '  //     //       pretendToBeVisual: true,\r\n' +
      "  //     //       resources: 'usable'\r\n" +
      '  //     //     }\r\n' +
      '  //     //   );\r\n' +
      '\r\n' +
      "  //     //   console.log('Rebooot!');\r\n" +
      '  //     // }\r\n' +
      '\r\n' +
      "  //     mocha.suite.on('pre-require', function () {\r\n" +
      '  //       // use tsconfig paths\r\n' +
      '  //       if (!global._tsconfigPathsRegistered) {\r\n' +
      "  //         require('tsconfig-paths').register();\r\n" +
      '  //         global._tsconfigPathsRegistered = true;\r\n' +
      '  //       }\r\n' +
      '  //       // extend expect\r\n' +
      "  //       // require(wallaby.projectCacheDir + '/src/compilers/java/lib/extendExpect');\r\n" +
      '  //     });\r\n' +
      '  //   }\r\n' +
      '  // };\r\n' +
      '};\r\n'
  },
  packageJSON: {
    dependencies: {
      '@apollo/client': '^3.2.5',
      '@babel/core': '^7.12.3',
      '@babel/plugin-proposal-class-properties': '^7.12.1',
      '@babel/plugin-proposal-decorators': '^7.12.1',
      '@babel/register': '^7.12.1',
      '@ckeditor/ckeditor5-react': '^3.0.2',
      '@emotion/core': '^10.0.35',
      '@emotion/styled': '^10.0.27',
      '@graphql-codegen/near-operation-file-preset': '^1.17.13',
      '@loadable/component': '^5.14.1',
      '@monaco-editor/react': '^4.2.1',
      '@next/bundle-analyzer': '^10.0.5',
      '@svgdotjs/svg.js': '^3.1.1',
      '@types/react-dom': '^17.0.8',
      'apollo-connector-mongodb': '^3.0.5',
      'apollo-link-batch-http': '^1.2.14',
      'apollo-link-schema': '^1.2.5',
      'apollo-link-token-refresh': '^0.3.2',
      'apollo-server-micro': '^2.18.2',
      'babel-loader': '^8.1.0',
      'babel-plugin-jsx-control-statements': '^4.1.0',
      bcryptjs: '^2.4.3',
      buzz: '^1.2.1',
      'ckeditor5-custom-build': './ckeditor',
      classnames: '^2.2.6',
      'cookie-cutter': '^0.2.0',
      cookies: '^0.8.0',
      cors: '^2.8.5',
      'date-fns': '^2.16.1',
      'diff-view': '^1.0.12',
      forever: '^3.0.4',
      glob: '^7.1.6',
      graphql: '^15.4.0',
      'highlight.js': '^11.0.1',
      'java-ast': '^0.3.0',
      'js-beautify': '^1.13.0',
      jsdom: '^16.6.0',
      jszip: '^3.5.0',
      'jwt-decode': '^3.1.2',
      keyboardjs: '^2.6.4',
      lodash: '^4.17.20',
      'loop-protect': 'git://github.com/tomitrescak/loop-protect.git',
      marked: '^0.3.17',
      'meteor-random': '^0.0.3',
      'meteor-sha256': '^1.0.1',
      mobx: '^6.0.1',
      'mobx-react': '^7.0.0',
      'mock-apollo-client': '^1.0.0',
      'monaco-editor': '^0.26.1',
      next: '^10.0.0',
      nodemailer: '^6.4.14',
      'python-ast': '^0.1.0',
      react: '17.0.1',
      'react-alert': '^7.0.2',
      'react-alert-template-basic': '^1.0.0',
      'react-color': '^2.19.3',
      'react-datepicker': '^3.3.0',
      'react-dom': '17.0.1',
      'react-helmet': '^6.1.0',
      'react-s3-uploader': '^5.0.0',
      'react-split-pane': '^0.1.92',
      'react-transition-group': '^4.4.1',
      'react-virtualized': '^9.22.2',
      'semantic-ui-css': '^2.4.1',
      'semantic-ui-react': '^2.0.1',
      'semantic-ui-react-numberinput': '^1.5.0',
      sinon: '^9.2.0',
      svgdom: '^0.1.8',
      sweetalert2: '^10.9.0',
      'ts-node': '^10.0.0',
      'tsconfig-paths': '^3.9.0',
      tslib: '^2.0.3',
      typescript: '^4.0.5',
      vega: '^5.20.2'
    },
    devDependencies: {
      '@graphql-codegen/cli': '^1.19.0',
      '@graphql-codegen/introspection': '^1.18.0',
      '@graphql-codegen/typescript': '^1.17.11',
      '@graphql-codegen/typescript-operations': '^1.17.8',
      '@graphql-codegen/typescript-react-apollo': '^2.0.7',
      '@graphql-codegen/typescript-resolvers': '^1.17.10',
      '@testing-library/jest-dom': '^5.14.1',
      '@testing-library/react': '^11.1.0',
      '@types/bcryptjs': '^2.4.2',
      '@types/classnames': '^2.2.11',
      '@types/jsdom': '^16.2.13',
      '@types/lodash': '^4.14.164',
      '@types/lru-cache': '^5.1.1',
      '@types/mocha': '^8.0.3',
      '@types/mongodb': '^3.5.32',
      '@types/node': '^14.14.5',
      '@types/nodemailer': '^6.4.0',
      '@types/react': '^16.9.54',
      '@types/react-alert': '^5.2.0',
      '@types/react-datepicker': '^3.1.1',
      '@types/react-helmet': '^6.1.0',
      '@types/react-transition-group': '^4.4.0',
      '@types/react-virtualized': '^9.21.10',
      '@types/sinon': '^9.0.8',
      '@typescript-eslint/eslint-plugin': '^4.6.0',
      '@typescript-eslint/parser': '^4.6.0',
      eslint: '^7.12.1',
      'eslint-config-prettier': '^6.15.0',
      'eslint-plugin-jsx-a11y': '^6.4.1',
      'eslint-plugin-prettier': '^3.1.4',
      'eslint-plugin-react-hooks': '^4.2.0',
      expect: '^26.6.1',
      'graphql-tools': '^7.0.1',
      'i18n-tag-schema': '^2.5.0',
      'jest-sinon': '^1.0.4',
      'jsdom-global': '^3.0.2',
      jsonwebtoken: '^8.5.1',
      mocha: '^8.2.0',
      'mongodb-memory-server': '^6.9.2',
      prettier: '^2.1.2',
      sinon: '^9.2.0'
    }
  },
  fs: { numberOfFiles: 1 },
  debug: [
    '2021-07-30T01:02:14.840Z project Wallaby Node version: v14.16.1\n',
    '2021-07-30T01:02:14.841Z project Wallaby config: C:\\Users\\tomi\\Projects\\Github\\clara\\wallaby.python.js\n',
    '2021-07-30T01:02:14.892Z project File cache: C:\\Users\\tomi\\.vscode\\extensions\\wallabyjs.wallaby-vscode-1.0.300\\projects\\bec7e6a62a11ed96\n',
    '2021-07-30T01:02:15.319Z uiService Listening port 51235\n',
    '2021-07-30T01:02:15.457Z workers Parallelism for initial run: 10, for regular run: 5\n',
    '2021-07-30T01:02:15.458Z workers Starting run worker instance #0\n',
    '2021-07-30T01:02:15.458Z workers Starting run worker instance #1\n',
    '2021-07-30T01:02:15.458Z workers Starting run worker instance #2\n',
    '2021-07-30T01:02:15.458Z workers Starting run worker instance #3\n',
    '2021-07-30T01:02:15.458Z workers Starting run worker instance #4\n',
    '2021-07-30T01:02:15.458Z workers Starting run worker instance #5\n',
    '2021-07-30T01:02:15.458Z workers Starting run worker instance #6\n',
    '2021-07-30T01:02:15.458Z workers Starting run worker instance #7\n',
    '2021-07-30T01:02:15.458Z workers Starting run worker instance #8\n',
    '2021-07-30T01:02:15.458Z workers Starting run worker instance #9\n',
    '2021-07-30T01:02:15.464Z workers Web server is listening at 57408\n',
    '2021-07-30T01:02:15.473Z project Stopping process pool\n',
    '2021-07-30T01:02:15.473Z project File cache is up-to-date, starting full test run\n',
    '2021-07-30T01:02:15.475Z project Running postprocessor\n',
    '2021-07-30T01:02:15.478Z postprocessor New TypeScript language service is required\n',
    "2021-07-30T01:02:15.478Z postprocessor TypeScript postprocessor will be removed because in 0 project files none were found by patterns: [ '**/*.ts?(x)' ]\n",
    '2021-07-30T01:02:15.482Z project Postprocessor execution finished\n',
    '2021-07-30T01:02:15.482Z project Postprocessor is removed as requested by itself\n',
    '2021-07-30T01:02:15.482Z project Test run started; run priority: 3\n',
    '2021-07-30T01:02:15.482Z project Running all tests\n',
    '2021-07-30T01:02:15.483Z project Test task priority upgraded to full run\n',
    '2021-07-30T01:02:15.485Z workers Starting test run, priority: 3\n',
    '2021-07-30T01:02:15.487Z chromeRunner Starting sandbox [worker #0, session #pu6qk]\n',
    '2021-07-30T01:02:18.036Z workers Started run worker instance (immediate) #0\n',
    '2021-07-30T01:02:18.036Z workers Started run worker instance (immediate) #1\n',
    '2021-07-30T01:02:18.036Z workers Started run worker instance (immediate) #2\n',
    '2021-07-30T01:02:18.036Z workers Started run worker instance (immediate) #3\n',
    '2021-07-30T01:02:18.036Z workers Started run worker instance (immediate) #4\n',
    '2021-07-30T01:02:18.036Z workers Started run worker instance (immediate) #5\n',
    '2021-07-30T01:02:18.037Z workers Started run worker instance (immediate) #6\n',
    '2021-07-30T01:02:18.037Z workers Started run worker instance (immediate) #7\n',
    '2021-07-30T01:02:18.037Z workers Started run worker instance (immediate) #8\n',
    '2021-07-30T01:02:18.037Z workers Started run worker instance (immediate) #9\n',
    '2021-07-30T01:02:18.037Z chromeRunner Preparing sandbox [worker #0, session #pu6qk]\n',
    '2021-07-30T01:02:18.037Z browserRunner Total files to load in sandbox: 0\n',
    '2021-07-30T01:02:18.038Z browserRunner Sandbox is generated [worker #0, session #pu6qk]: http://localhost:57408/wallaby_sandbox0.html\n',
    '2021-07-30T01:02:18.038Z chromeRunner Prepared sandbox [worker #0, session #pu6qk]\n',
    '2021-07-30T01:02:18.038Z workers [worker #0, session #pu6qk] Running tests in sandbox\n',
    '2021-07-30T01:02:18.195Z workers [pu6qk] Loaded 0 test(s)\n',
    '2021-07-30T01:02:18.199Z workers [pu6qk] Run 0 test(s), skipped 0 test(s)\n',
    '2021-07-30T01:02:18.203Z workers [pu6qk] Sandbox is responsive, closing it\n',
    '2021-07-30T01:02:18.206Z project Test run finished\n',
    '2021-07-30T01:02:18.206Z project Processed console.log entries\n',
    '2021-07-30T01:02:18.206Z project Processed loading sequences\n',
    '2021-07-30T01:02:18.206Z project Processed executed tests\n',
    '2021-07-30T01:02:18.206Z project Processed code coverage\n',
    '2021-07-30T01:02:18.212Z project Test run result processed and sent to IDE\n',
    '2021-07-30T01:02:18.230Z project TypeScript file has been added, re-activating TypeScript postprocessor\n',
    '2021-07-30T01:02:18.230Z project Running postprocessor\n',
    '2021-07-30T01:02:18.230Z testTask Test files from affected: 0, from deleted or manually requested: 0, from recently changed: 0, from loaded by: 0, from failing: 0\n',
    '2021-07-30T01:02:18.232Z postprocessor New TypeScript language service is required\n',
    '2021-07-30T01:02:18.603Z project Postprocessor execution finished\n',
    '2021-07-30T01:02:18.603Z project Test run started; run priority: 2\n',
    '2021-07-30T01:02:18.604Z testTask Test files from affected: 0, from deleted or manually requested: 0, from recently changed: 0, from loaded by: 0, from failing: 0\n',
    '2021-07-30T01:02:18.605Z project Test task priority upgraded to full run\n',
    '2021-07-30T01:02:18.605Z workers Starting test run, priority: 3\n',
    '2021-07-30T01:02:18.605Z chromeRunner Starting sandbox [worker #0, session #w3211]\n',
    '2021-07-30T01:02:18.606Z chromeRunner Preparing sandbox [worker #0, session #w3211]\n',
    '2021-07-30T01:02:18.606Z browserRunner Total files to load in sandbox: 1\n',
    '2021-07-30T01:02:18.606Z browserRunner Sandbox is generated [worker #0, session #w3211]: http://localhost:57408/wallaby_sandbox0.html\n',
    '2021-07-30T01:02:18.606Z chromeRunner Prepared sandbox [worker #0, session #w3211]\n',
    '2021-07-30T01:02:18.606Z workers [worker #0, session #w3211] Running tests in sandbox\n',
    '2021-07-30T01:02:18.788Z workers Sandbox (active) [w3211] error: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:02:18.790Z workers Failed to map the stack to user code, entry message: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../"., stack: TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:02:18.820Z workers Sandbox (active) [w3211] error: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:02:18.821Z workers Failed to map the stack to user code, entry message: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../"., stack: TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:02:18.834Z workers [w3211] Loaded 0 test(s)\n',
    '2021-07-30T01:02:18.839Z workers [w3211] Run 0 test(s), skipped 0 test(s)\n',
    '2021-07-30T01:02:18.841Z workers [w3211] Sandbox is responsive, closing it\n',
    '2021-07-30T01:02:18.843Z project Test run finished\n',
    '2021-07-30T01:02:18.843Z project Processed console.log entries\n',
    '2021-07-30T01:02:18.843Z project Processed loading sequences\n',
    '2021-07-30T01:02:18.843Z project Processed executed tests\n',
    '2021-07-30T01:02:18.843Z project Processed code coverage\n',
    '2021-07-30T01:02:18.851Z project Test run result processed and sent to IDE\n',
    '2021-07-30T01:05:45.379Z fs File changed in editor: src/compilers/python/tests/load.test.ts\n',
    '2021-07-30T01:05:45.404Z project Running postprocessor\n',
    '2021-07-30T01:05:45.405Z testTask Test files from affected: 0, from deleted or manually requested: 0, from recently changed: 0, from loaded by: 0, from failing: 0\n',
    '2021-07-30T01:05:45.448Z project Postprocessor execution finished\n',
    '2021-07-30T01:05:45.448Z project Test run started; run priority: 2\n',
    '2021-07-30T01:05:45.448Z testTask Test files from affected: 0, from deleted or manually requested: 0, from recently changed: 0, from loaded by: 0, from failing: 0\n',
    '2021-07-30T01:05:45.448Z project Test task priority upgraded to full run\n',
    '2021-07-30T01:05:45.448Z workers Starting test run, priority: 3\n',
    '2021-07-30T01:05:45.448Z chromeRunner Starting sandbox [worker #0, session #fbp8m]\n',
    '2021-07-30T01:05:45.449Z chromeRunner Preparing sandbox [worker #0, session #fbp8m]\n',
    '2021-07-30T01:05:45.449Z browserRunner Total files to load in sandbox: 1\n',
    '2021-07-30T01:05:45.449Z browserRunner Sandbox is generated [worker #0, session #fbp8m]: http://localhost:57408/wallaby_sandbox0.html\n',
    '2021-07-30T01:05:45.449Z chromeRunner Prepared sandbox [worker #0, session #fbp8m]\n',
    '2021-07-30T01:05:45.449Z workers [worker #0, session #fbp8m] Running tests in sandbox\n',
    '2021-07-30T01:05:45.603Z workers [fbp8m] Loaded 1 test(s)\n',
    '2021-07-30T01:05:45.612Z workers [fbp8m] Test executed: loads brython\n',
    '2021-07-30T01:05:45.622Z workers [fbp8m] Run 1 test(s), skipped 0 test(s)\n',
    '2021-07-30T01:05:45.625Z workers [fbp8m] Sandbox is responsive, closing it\n',
    '2021-07-30T01:05:45.627Z project Test run finished\n',
    '2021-07-30T01:05:45.627Z project Processed console.log entries\n',
    '2021-07-30T01:05:45.627Z project Processed loading sequences\n',
    '2021-07-30T01:05:45.628Z project Processed executed tests\n',
    '2021-07-30T01:05:45.629Z project Processed code coverage\n',
    '2021-07-30T01:05:45.632Z project Test run result processed and sent to IDE\n',
    '2021-07-30T01:05:50.580Z fs File changed in editor: src/compilers/python/tests/load.test.ts\n',
    '2021-07-30T01:05:50.602Z project Running postprocessor\n',
    '2021-07-30T01:05:50.602Z testTask Test files from affected: 0, from deleted or manually requested: 0, from recently changed: 0, from loaded by: 0, from failing: 0\n',
    '2021-07-30T01:05:50.636Z project Postprocessor execution finished\n',
    '2021-07-30T01:05:50.636Z project Test run started; run priority: 2\n',
    '2021-07-30T01:05:50.636Z testTask Test files from affected: 0, from deleted or manually requested: 0, from recently changed: 0, from loaded by: 0, from failing: 0\n',
    '2021-07-30T01:05:50.637Z project Test task priority upgraded to full run\n',
    '2021-07-30T01:05:50.637Z workers Starting test run, priority: 3\n',
    '2021-07-30T01:05:50.637Z chromeRunner Starting sandbox [worker #0, session #t4z19]\n',
    '2021-07-30T01:05:50.637Z chromeRunner Preparing sandbox [worker #0, session #t4z19]\n',
    '2021-07-30T01:05:50.637Z browserRunner Total files to load in sandbox: 1\n',
    '2021-07-30T01:05:50.637Z browserRunner Sandbox is generated [worker #0, session #t4z19]: http://localhost:57408/wallaby_sandbox0.html\n',
    '2021-07-30T01:05:50.637Z chromeRunner Prepared sandbox [worker #0, session #t4z19]\n',
    '2021-07-30T01:05:50.638Z workers [worker #0, session #t4z19] Running tests in sandbox\n',
    '2021-07-30T01:05:50.779Z workers Sandbox (active) [t4z19] error: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:05:50.780Z workers Failed to map the stack to user code, entry message: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../"., stack: TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:05:50.796Z workers Sandbox (active) [t4z19] error: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:05:50.796Z workers Failed to map the stack to user code, entry message: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../"., stack: TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:05:50.810Z workers [t4z19] Loaded 0 test(s)\n',
    '2021-07-30T01:05:50.815Z workers [t4z19] Run 0 test(s), skipped 0 test(s)\n',
    '2021-07-30T01:05:50.817Z workers [t4z19] Sandbox is responsive, closing it\n',
    '2021-07-30T01:05:50.819Z project Test run finished\n',
    '2021-07-30T01:05:50.819Z project Processed console.log entries\n',
    '2021-07-30T01:05:50.819Z project Processed loading sequences\n',
    '2021-07-30T01:05:50.819Z project Processed executed tests\n',
    '2021-07-30T01:05:50.819Z project Processed code coverage\n',
    '2021-07-30T01:05:50.822Z project Test run result processed and sent to IDE\n',
    '2021-07-30T01:06:00.849Z fs File changed in editor: src/compilers/python/tests/load.test.ts\n',
    '2021-07-30T01:06:00.857Z project Running postprocessor\n',
    '2021-07-30T01:06:00.857Z testTask Test files from affected: 0, from deleted or manually requested: 0, from recently changed: 0, from loaded by: 0, from failing: 0\n',
    '2021-07-30T01:06:00.901Z project Postprocessor execution finished\n',
    '2021-07-30T01:06:00.902Z project Test run started; run priority: 2\n',
    '2021-07-30T01:06:00.902Z testTask Test files from affected: 0, from deleted or manually requested: 0, from recently changed: 0, from loaded by: 0, from failing: 0\n',
    '2021-07-30T01:06:00.902Z project Test task priority upgraded to full run\n',
    '2021-07-30T01:06:00.902Z workers Starting test run, priority: 3\n',
    '2021-07-30T01:06:00.902Z chromeRunner Starting sandbox [worker #0, session #aceqd]\n',
    '2021-07-30T01:06:00.903Z chromeRunner Preparing sandbox [worker #0, session #aceqd]\n',
    '2021-07-30T01:06:00.903Z browserRunner Total files to load in sandbox: 1\n',
    '2021-07-30T01:06:00.903Z browserRunner Sandbox is generated [worker #0, session #aceqd]: http://localhost:57408/wallaby_sandbox0.html\n',
    '2021-07-30T01:06:00.903Z chromeRunner Prepared sandbox [worker #0, session #aceqd]\n',
    '2021-07-30T01:06:00.903Z workers [worker #0, session #aceqd] Running tests in sandbox\n',
    '2021-07-30T01:06:01.031Z workers Sandbox (active) [aceqd] error: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:06:01.031Z workers Failed to map the stack to user code, entry message: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../"., stack: TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:06:01.047Z workers Sandbox (active) [aceqd] error: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:06:01.047Z workers Failed to map the stack to user code, entry message: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../"., stack: TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:06:01.062Z workers [aceqd] Loaded 0 test(s)\n',
    '2021-07-30T01:06:01.067Z workers [aceqd] Run 0 test(s), skipped 0 test(s)\n',
    '2021-07-30T01:06:01.069Z workers [aceqd] Sandbox is responsive, closing it\n',
    '2021-07-30T01:06:01.071Z project Test run finished\n',
    '2021-07-30T01:06:01.071Z project Processed console.log entries\n',
    '2021-07-30T01:06:01.071Z project Processed loading sequences\n',
    '2021-07-30T01:06:01.071Z project Processed executed tests\n',
    '2021-07-30T01:06:01.071Z project Processed code coverage\n',
    '2021-07-30T01:06:01.073Z project Test run result processed and sent to IDE\n',
    '2021-07-30T01:06:03.538Z fs File changed: src/compilers/python/tests/load.test.ts\n',
    '2021-07-30T01:06:03.601Z project Running postprocessor\n',
    '2021-07-30T01:06:03.601Z testTask Test files from affected: 0, from deleted or manually requested: 0, from recently changed: 0, from loaded by: 0, from failing: 0\n',
    '2021-07-30T01:06:03.621Z project Postprocessor execution finished\n',
    '2021-07-30T01:06:03.622Z project Test run started; run priority: 2\n',
    '2021-07-30T01:06:03.622Z testTask Test files from affected: 0, from deleted or manually requested: 0, from recently changed: 0, from loaded by: 0, from failing: 0\n',
    '2021-07-30T01:06:03.622Z project Test task priority upgraded to full run\n',
    '2021-07-30T01:06:03.622Z workers Starting test run, priority: 3\n',
    '2021-07-30T01:06:03.622Z chromeRunner Starting sandbox [worker #0, session #1rez3]\n',
    '2021-07-30T01:06:03.622Z chromeRunner Preparing sandbox [worker #0, session #1rez3]\n',
    '2021-07-30T01:06:03.623Z browserRunner Total files to load in sandbox: 1\n',
    '2021-07-30T01:06:03.623Z browserRunner Sandbox is generated [worker #0, session #1rez3]: http://localhost:57408/wallaby_sandbox0.html\n',
    '2021-07-30T01:06:03.623Z chromeRunner Prepared sandbox [worker #0, session #1rez3]\n',
    '2021-07-30T01:06:03.623Z workers [worker #0, session #1rez3] Running tests in sandbox\n',
    '2021-07-30T01:06:03.662Z fs File changed in editor: src/compilers/python/tests/load.test.ts\n',
    '2021-07-30T01:06:03.662Z fs No changes detected for src/compilers/python/tests/load.test.ts\n',
    '2021-07-30T01:06:03.663Z extended-core File was not changed, but file markers may need to be synced\n',
    '2021-07-30T01:06:03.758Z workers Sandbox (active) [1rez3] error: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:06:03.759Z workers Failed to map the stack to user code, entry message: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../"., stack: TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:06:03.819Z workers Sandbox (active) [1rez3] error: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:06:03.819Z workers Failed to map the stack to user code, entry message: Uncaught TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../"., stack: TypeError: Failed to resolve module specifier "expect". Relative references must start with either "/", "./", or "../".\n',
    '2021-07-30T01:06:03.830Z workers [1rez3] Loaded 0 test(s)\n',
    '2021-07-30T01:06:03.835Z workers [1rez3] Run 0 test(s), skipped 0 test(s)\n',
    '2021-07-30T01:06:03.837Z workers [1rez3] Sandbox is responsive, closing it\n',
    '2021-07-30T01:06:03.838Z project Test run finished\n',
    '2021-07-30T01:06:03.839Z project Processed console.log entries\n',
    '2021-07-30T01:06:03.839Z project Processed loading sequences\n',
    '2021-07-30T01:06:03.839Z project Processed executed tests\n',
    '2021-07-30T01:06:03.839Z project Processed code coverage\n',
    '2021-07-30T01:06:03.840Z project Test run result processed and sent to IDE\n'
  ]
}
tomitrescak commented 3 years ago

This is another config I tried:

// @ts-nocheck1
// eslint-disable-next-line @typescript-eslint/no-var-requires
module.exports = function (wallaby) {
  return {
    files: ['src/compilers/python/**/*.ts', '!src/compilers/python/**/*.test.ts'],
    tests: ['src/compilers/python/**/*.test.ts'],
    testFramework: 'mocha',
    compilers: {
      '**/*.ts?(x)': wallaby.compilers.babel({
        presets: ['next/babel'],
        plugins: [
          ['@babel/plugin-proposal-decorators', { legacy: true }],
          ['@babel/plugin-proposal-class-properties', { loose: true }]
        ]
      })
    },
    env: {
      type: 'node',
      runner: 'node'
    },
    setup: function (wallaby) {
      const { JSDOM } = require('jsdom');

      const options = {
        runScripts: 'dangerously',
        resources: 'usable'
      };
      global.window = new JSDOM(
        `
        <!DOCTYPE html><html><body><div id="test"></div><script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.5/brython.min.js"></script></body></html>
      `,
        options
      );
    }
  };
};
smcenlly commented 3 years ago

For browser-based tests (NOT using node), this should work for you with the wallaby-typescript-sample:

wallaby.js

module.exports = function (w) {
  return {
    files: ['src/index.html', 'src/*Browser.ts'],

    tests: ['test/*BrowserSpec.ts'],

    setup: function () {
      // return a promise and don't resolve/reject it until the CDN script has loaded.
      return new Promise(function (resolve, reject) {
        var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.onload = resolve;
        script.onerror = reject;
        script.src = 'https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.5/brython.min.js';
        head.appendChild(script);
      });
    },
  };
};

I'm going to take a quick look to see if you can do a similar thing with JSDOM.

smcenlly commented 3 years ago

I can't seem to get JSDOM to load brython. If you want to take this approach, you should try get it loading outside of Wallaby first.

I should also note that it's less than ideal to go and download from the CDN each time, even if it is cached. As a best practice, we recommend downloading the library for when your tests are running, even if this isn't what you do in your production runtime. It will be faster and less fragile.

tomitrescak commented 3 years ago

Thank you very much @smcenlly