gpt4 book ai didi

javascript - 夜巡通天塔 7 设置 : Unexpected identifier

转载 作者:行者123 更新时间:2023-12-03 00:06:28 24 4
gpt4 key购买 nike

我最近在我的 React 项目中尝试了 Babel 7。尽管升级路径很复杂,但实际上相当顺利。然而,我被 Babel 7 的 Nightwatch 设置困住了。我能找到的所有文档都涉及 Babel 6,它们有些不同。我仍然尝试尽我所能,但我陷入了某个点,没有解决办法。我使用的是 React 16.8.3、Nightwatch 1.0.18 和 Babel 7,我按照官方文档更新了所有依赖项。

这是我的夜巡配置:

require('@babel/register')({
extends: './.babelrc',
extensions: '.js',
});

const reportBucket = 'admin';
const reportFolder = `./reports/${reportBucket}`;
const screenshotFolder = `/nightwatch/screenshots/${reportBucket}`;

module.exports = {
src_folders: ['./specs'],
output_folder: reportFolder,
page_objects_path: './pages',
custom_commands_path: './commands',
globals_path: './globals.js',
test_settings: {
default: {
launch_url: process.env.TEST_URL.replace(':443', ''),
selenium_host: process.env.SELENIUM_HOST,
selenium_port: process.env.SELENIUM_PORT,
silent: true,
end_session_on_fail: false, // keep session open to get screenshot on teardown
use_xpath: true,
request_timeout_options: {
timeout: 300000,
},
screenshots: {
enabled: true,
path: screenshotFolder,
on_failure: true,
on_error: true,
},
desiredCapabilities: {
'browserstack.use_w3c': 'true',
'browserstack.user': process.env.BROWSERSTACK_USER,
'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY,
'browserstack.local': true,
'browserstack.localIdentifier': process.env.BROWSERSTACK_LOCAL_ID,
'browserstack.selenium_version': process.env.SELENIUM_VERSION,
project: 'TEST',
build: process.env.BUILD_TAG,
name: process.env.SELENIUM_BROWSERS,
resolution: '1920x1080',
javascriptEnabled: true,
acceptSslCerts: true,
browserName: 'chrome',
acceptInsecureCerts: true,
},
},
chrome: {
desiredCapabilities: {
os: 'windows',
os_version: '10',
browserName: 'chrome',
browser_version: '71.0',
'goog:chromeOptions': {
args: [
'--enable-automation',
'--disable-web-security',
'--disable-infobars',
],
},
},
},
firefox: {
desiredCapabilities: {
/*
react-select does not work when the browser is not
the app in focus in the OS.
This was failing all tests that included this component
so we exculsively run on windows on browserstack
to avoid this issue
the core of the issue is that when firefox not in focus, 'mousedown'
is not triggered. All other selenium events seem fine (click, key, etc)
*/
os: 'windows',
os_version: '10',
browserName: 'firefox',
browser_version: '64.0',
marionette: true,
acceptInsecureCerts: true,
},
},
ie11: {
desiredCapabilities: {
/*
windows 10 needed so input values are
cleared and set properly. win 8 driver has issues
*/
os: 'windows',
os_version: '10',
browserName: 'ie',
browser_version: '11.0',
acceptInsecureCerts: true,
},
},
edge: {
desiredCapabilities: {
os: 'windows',
os_version: '10',
browserName: 'edge',
browser_version: '17.0',
acceptInsecureCerts: true,
},
},
},
parallel_process_delay: 1000,
live_output: true,
test_workers: {
enabled: true,
workers: parseInt(process.env.TEST_WORKERS, 10) || 1,
},
};

请注意,我在顶部使用了@babel/register(从 babel-register 升级

关注此帖子后:https://babeljs.io/docs/en/v7-migration我还为我的 Nightwatch 测试服更新了 .babelrc,如下所示:

{
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"node": "current"
}
}
]
]
}

使用此配置,如果我尝试运行任何 Nightwatch 测试,我将得到以下结果:

  TEST FAILURE: 1 error during execution 0 tests failed, 0 passed. 104ms

Unexpected identifier
import test from '../../../lib/random';
^^^^

SyntaxError: Unexpected identifier
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)

有人能解决类似的问题吗?我尝试了不同的 babel 配置,但似乎无法使其工作。

最佳答案

好吧,经过一番研究,我发现了 babel 7 的 babel 配置可以解决这个问题:

{
"presets": [
[
"@babel/preset-env",
{
"modules": "commonjs",
"targets": {
"node": "current"
}
}
]
],
"plugins": [
"add-module-exports",
]
}

关于javascript - 夜巡通天塔 7 设置 : Unexpected identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54930706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com