Я тестирую приложение Vue js с Nightwatch.Поскольку я интегрировал тестирование в свой gitlab ci / cd, мне нужны две разные конфигурации Nightwatch.
Чтобы добиться этого, я сделал следующее:
создав два разных скрипта для локального теста и теста gitlab
"scripts" : {
"e2e" : "node test/e2e/gitlab_runner.js" ,
"local-test" : "node test/e2e/local_runner.js" ,
"test": "npm run e2e"
Затем я вставляю нужную мне переменную в файлы local_runner
и gilab_runner
process.env.NIGHTWATCH_CONFIG = 'nightwatch.local.js';
require('./runner.js');
и для gitlab_runner
process.env.NIGHTWATCH_CONFIG = 'nightwatch.conf.js';
require('./runner.js');
затем в файле runner.js
у меня есть следующая строка кода
opts = opts.concat(['--config', 'test/e2e/' + NIGHTWATCH_CONFIG]);
, поэтому я могу получить правильный файл.
Проблема в том, что при запуске сценария я получаю следующееошибка:
(node:21061) UnhandledPromiseRejectionWarning: ReferenceError: NIGHTWATCH_CONFIG is not defined
at devConfigPromise.then.then (xxxxxx/test/e2e/runner.js:30:51)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:182:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:697:11)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
(node:21061) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:21061) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Я также попытался сделать следующее в файлах local_runner
и gitlab_runner
:
module.exports = {
NIGHTWATCH_CONFIG = 'nightwatch.local.js';
};
Но затем переменная NIGHTWATCH_CONFIG
в runner.js
файл не определен.
Как я могу решить эту проблему?