Wdio / TypeScript - Не удается найти модуль при запуске теста в BitBucket-конвейерах - PullRequest
0 голосов
/ 15 июня 2019

У меня есть проект webdriverio / typescript (использующий Page Object), который предназначен для работы на конвейерах BitBucket. Когда я запускаю тест локально, все работает правильно, но когда я нажимаю на Bitbucket, конвейер не проходит, ни один из тестов не будет запущен.

Журнал BitBucket-конвейеров:

[0-0] RUNNING in chrome - /specs/login.spec.ts
[0-0] https://automation-company.staging.singlecase.cz
[0-0] 2019-06-14T21:49:52.327Z ERROR @wdio/runner: Error: Cannot find module '@Pages/LoginPage'

BitBucket-pipelines.yml

image: node:10.15.3

pipelines: 
  default: 
    - step: 
        script: 
          - apt update && apt install default-jre -y
          - npm install
          - echo "Run tests!"
          - ENV='staging' HEADLESS=true npm test
        services: 
          - selenium
 definitions: 
  services: 
    selenium: 
      image: selenium/standalone-chrome

здесь wdio.conf.js

const timeout = process.env.DEBUG ? 99999999 : 90000;

let chromeArgs = ['--no-sandbox', "window-size=1920,1080", 'disable-infobars', 'disable-extensions', '--lang=en-us', '--disable-dev-shm-usage'];

if(process.env.HEADLESS === 'true') {
  chromeArgs.push('--headless');
}

exports.config = {

    runner: 'local',
    host: 'localhost',
    port: 4444,

    specs: [
      './specs/login.spec.ts',
  ],

    maxInstances: 2,

    capabilities: [{
        maxInstances: 2,
        browserName: 'chrome',
        'goog:chromeOptions': {
            args: chromeArgs
        }
    }],

    logLevel: 'error',
    deprecationWarnings: true,
    bail: 0,
    baseUrl: serverURL,
    waitforTimeout: 10000,
    connectionRetryTimeout: 90000,
    connectionRetryCount: 3,
    services: ['selenium-standalone'],
    framework: 'mocha',
    mochaOpts: {
      compilers: [
        'tsconfig-paths/register'
      ],
        ui: 'bdd',
        retries: 2,
        timeout: timeout
    },

    before: function () {
      require('ts-node').register({ files: true });
      console.log(browser.options.baseUrl);
    },

и, наконец, файл tsconfig.js здесь

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@Specs/*":         ["./specs/*"],
      "@Pages/*":         ["./src/pages/*"],
      "@Helpers/*":       ["./helpers/*"]
    },

    "target": "es2017",                       /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */

    "strict": true,                           /* Enable all strict type-checking options. */
    "noImplicitAny": false,                   /* Raise error on expressions and declarations with an implied 'any' type. */
                 /* List of folders to include type definitions from. */
    "types": ["@wdio/sync","mocha", "node"],  /* Type declaration files to be included in compilation. */
    // "types": ["webdriverio","mocha", "node"],
    "allowSyntheticDefaultImports": true,     /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
    "esModuleInterop": true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
  }
}

вот пример того, как я импортирую модули:

import  LoginPage from '@Pages/LoginPage';

import { expect } from 'chai';

import USERS from '@Helpers/users';
import PATH from '@Helpers/urls';

Имейте в виду, что локально это работает, на CI это не работает.

...