GitHub Action Mocha测试中未识别的命令

发布于 2025-02-12 15:49:59 字数 7338 浏览 0 评论 0原文

当地运行时,我的单位测试通过。当通过github操作执行分支时,此操作

on:
  push:
    branches:    
      - '*'         # matches every branch that doesn't contain a '/'
      - '*/*'       # matches every branch containing a single '/'
      - '**'        # matches every branch
      - '!master'   # excludes master

  workflow_dispatch:
    inputs:
      build:
        description: Unit tests
        type: boolean
        required: true
        default: "true"

jobs:
  build:
    strategy:
      matrix:
        os: [windows-latest]
        # os: [ubuntu-latest, windows-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Install Node.js
      uses: actions/setup-node@v1
      with:
        node-version: 16.x
    - run: npm install
    - run: npm i gulp gulp-cli -g
      if: runner.os == 'MacOS'
    - run: gulp
    - run: xvfb-run -a npm test
      if: runner.os == 'Linux'
    - run: npm test
      if: runner.os != 'Linux'

基本上运行npm test

当我在本地这样做时,它可以正常工作:

npm test

> [email protected] test
> node ./out/test/runTest.js

Debugger listening on ws://127.0.0.1:63067/252bd7f9-c748-45b4-b9e6-8ba21e9fc909
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Found existing install in C:\Users\Peter\source\vsc-print\.vscode-test\vscode-win32-x64-archive-1.68.1. Skipping download

[16792:0704/000228.095:ERROR:node_bindings.cc(286)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details.       
[16792:0704/000228.095:ERROR:node_bindings.cc(286)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details.       
[main 2022-07-03T14:02:28.455Z] update#ctor - updates are disabled by the environment
[main 2022-07-03T14:02:29.679Z] Starting extension host with pid 32 (fork() took 15 ms).
Loading development extension at c:\Users\Peter\source\vsc-print
Decryption failed

  Print Extension Test Suite
    ✔ Check platform browser launch command on win32 (200ms)
    ✔ Check platform alternate browser launch command on win32 (112ms)
    ✔ Print active editor (304ms)
Could not find the language 'jsonc', did you forget to load/include a language module?
    ✔ Print folder (812ms)
  4 passing (2s)
[main 2022-07-03T14:02:32.887Z] Extension host with pid 32 exited with code: 0, signal: null.
Exit code:   0
Done

Waiting for the debugger to disconnect...

当操作运行时,这是输出。

Downloaded VS Code into D:\a\vsc-print\vsc-print\.vscode-test\vscode-win32-x64-archive-1.68.1
[main 2022-07-03T13:06:32.496Z] update#ctor - updates are disabled by the environment
workbench#open()
[main 2022-07-03T13:06:37.868Z] Calling fork to start extension host...
[main 2022-07-03T13:06:37.879Z] Starting extension host with pid 776 (fork() took 11 ms).
IExtensionHostStarter.start() took 42 ms.
Loading development extension at d:\a\vsc-print\vsc-print
  Print Extension Test Suite
    1) Check platform browser launch command on win32
Error: 4 tests failed.
    2) Check platform alternate browser launch command on win32
    3) Print active editor
    at d:\a\vsc-print\vsc-print\out\test\suite\index.js:25:27
    4) Print folder
    at done (d:\a\vsc-print\vsc-print\node_modules\mocha\lib\mocha.js:1009:7)
  0 passing (518ms)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
  4 failing
  1) Print Extension Test Suite
       Check platform browser launch command on win32:
     Error: command 'extension.test.browserLaunchCommand' not found
      at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
      at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
  2) Print Extension Test Suite
       Check platform alternate browser launch command on win32:
     Error: command 'extension.test.browserLaunchCommand' not found
      at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
      at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
  3) Print Extension Test Suite
       Print active editor:
     Error: command 'extension.test.flags' not found
      at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
      at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
  4) Print Extension Test Suite
       Print folder:
     Error: command 'extension.test.flags' not found
      at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
      at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
[main 2022-07-03T13:06:41.294Z] Waiting for extension host with pid 776 to exit.
[main 2022-07-03T13:06:41.330Z] Extension host with pid 776 exited with code: 1, signal: null.
Exit code:   1
Failed
Failed to run tests
Error: Process completed with exit code 1.

未识别的命令已在扩展激活事件的开始附近注册。

export function activate(context: vscode.ExtensionContext) {
    let ecmPrint = vscode.workspace.getConfiguration("print", null).editorContextMenuItemPosition,
        etmButton = vscode.workspace.getConfiguration("print", null).editorTitleMenuButton,
        disposable: vscode.Disposable;
    vscode.commands.executeCommand("setContext", "ecmPrint", ecmPrint);
    vscode.commands.executeCommand("setContext", "etmButton", etmButton);

    context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(checkConfigurationChange));
    context.subscriptions.push(vscode.commands.registerCommand("extension.print", printCommand));
    context.subscriptions.push(vscode.commands.registerCommand("extension.printFolder", printFolderCommand));
    context.subscriptions.push(vscode.commands.registerCommand("extension.test.flags", () => testFlags));
    context.subscriptions.push(vscode.commands.registerCommand("extension.test.browserLaunchCommand", PrintSession.getLaunchBrowserCommand));

这表明尚未调用激活方法。这是我必须明确做的事情吗?

My unit tests pass when run locally. When executed by a GitHub Action when a branch is committed, this action

on:
  push:
    branches:    
      - '*'         # matches every branch that doesn't contain a '/'
      - '*/*'       # matches every branch containing a single '/'
      - '**'        # matches every branch
      - '!master'   # excludes master

  workflow_dispatch:
    inputs:
      build:
        description: Unit tests
        type: boolean
        required: true
        default: "true"

jobs:
  build:
    strategy:
      matrix:
        os: [windows-latest]
        # os: [ubuntu-latest, windows-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Install Node.js
      uses: actions/setup-node@v1
      with:
        node-version: 16.x
    - run: npm install
    - run: npm i gulp gulp-cli -g
      if: runner.os == 'MacOS'
    - run: gulp
    - run: xvfb-run -a npm test
      if: runner.os == 'Linux'
    - run: npm test
      if: runner.os != 'Linux'

basically runs npm test.

When I do that locally, it works fine:

npm test

> [email protected] test
> node ./out/test/runTest.js

Debugger listening on ws://127.0.0.1:63067/252bd7f9-c748-45b4-b9e6-8ba21e9fc909
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Found existing install in C:\Users\Peter\source\vsc-print\.vscode-test\vscode-win32-x64-archive-1.68.1. Skipping download

[16792:0704/000228.095:ERROR:node_bindings.cc(286)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details.       
[16792:0704/000228.095:ERROR:node_bindings.cc(286)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details.       
[main 2022-07-03T14:02:28.455Z] update#ctor - updates are disabled by the environment
[main 2022-07-03T14:02:29.679Z] Starting extension host with pid 32 (fork() took 15 ms).
Loading development extension at c:\Users\Peter\source\vsc-print
Decryption failed

  Print Extension Test Suite
    ✔ Check platform browser launch command on win32 (200ms)
    ✔ Check platform alternate browser launch command on win32 (112ms)
    ✔ Print active editor (304ms)
Could not find the language 'jsonc', did you forget to load/include a language module?
    ✔ Print folder (812ms)
  4 passing (2s)
[main 2022-07-03T14:02:32.887Z] Extension host with pid 32 exited with code: 0, signal: null.
Exit code:   0
Done

Waiting for the debugger to disconnect...

When the Action runs it, this is the output.

Downloaded VS Code into D:\a\vsc-print\vsc-print\.vscode-test\vscode-win32-x64-archive-1.68.1
[main 2022-07-03T13:06:32.496Z] update#ctor - updates are disabled by the environment
workbench#open()
[main 2022-07-03T13:06:37.868Z] Calling fork to start extension host...
[main 2022-07-03T13:06:37.879Z] Starting extension host with pid 776 (fork() took 11 ms).
IExtensionHostStarter.start() took 42 ms.
Loading development extension at d:\a\vsc-print\vsc-print
  Print Extension Test Suite
    1) Check platform browser launch command on win32
Error: 4 tests failed.
    2) Check platform alternate browser launch command on win32
    3) Print active editor
    at d:\a\vsc-print\vsc-print\out\test\suite\index.js:25:27
    4) Print folder
    at done (d:\a\vsc-print\vsc-print\node_modules\mocha\lib\mocha.js:1009:7)
  0 passing (518ms)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
  4 failing
  1) Print Extension Test Suite
       Check platform browser launch command on win32:
     Error: command 'extension.test.browserLaunchCommand' not found
      at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
      at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
  2) Print Extension Test Suite
       Check platform alternate browser launch command on win32:
     Error: command 'extension.test.browserLaunchCommand' not found
      at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
      at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
  3) Print Extension Test Suite
       Print active editor:
     Error: command 'extension.test.flags' not found
      at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
      at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
  4) Print Extension Test Suite
       Print folder:
     Error: command 'extension.test.flags' not found
      at v._tryExecuteCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3532)
      at v.executeCommand (vscode-file://vscode-app/d:/a/vsc-print/vsc-print/.vscode-test/vscode-win32-x64-archive-1.68.1/resources/app/out/vs/workbench/workbench.desktop.main.js:1706:3414)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
[main 2022-07-03T13:06:41.294Z] Waiting for extension host with pid 776 to exit.
[main 2022-07-03T13:06:41.330Z] Extension host with pid 776 exited with code: 1, signal: null.
Exit code:   1
Failed
Failed to run tests
Error: Process completed with exit code 1.

The unrecognised commands are registered near the start of the extension's activation event.

export function activate(context: vscode.ExtensionContext) {
    let ecmPrint = vscode.workspace.getConfiguration("print", null).editorContextMenuItemPosition,
        etmButton = vscode.workspace.getConfiguration("print", null).editorTitleMenuButton,
        disposable: vscode.Disposable;
    vscode.commands.executeCommand("setContext", "ecmPrint", ecmPrint);
    vscode.commands.executeCommand("setContext", "etmButton", etmButton);

    context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(checkConfigurationChange));
    context.subscriptions.push(vscode.commands.registerCommand("extension.print", printCommand));
    context.subscriptions.push(vscode.commands.registerCommand("extension.printFolder", printFolderCommand));
    context.subscriptions.push(vscode.commands.registerCommand("extension.test.flags", () => testFlags));
    context.subscriptions.push(vscode.commands.registerCommand("extension.test.browserLaunchCommand", PrintSession.getLaunchBrowserCommand));

This suggests that the activation method hasn't been called. Is this something I must do explicitly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖心男生 2025-02-19 15:49:59

我只是注意到这是extension.test.ts的顶部,

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';

这不是我的测试的编写方式。他们不导入代码并直接调用它,他们假设扩展名是安装和活动性的,并且使用注册命令。除了允许细颗粒单位测试外,没有其他原因添加了其中一些命令。

我在问题中描述的问题是由于未安装扩展名的事实。

发现我可以从扩展名中导入并不能解决所有问题。我的一些测试严格来说是说话的集成测试。他们需要安装和活动的扩展名。

为了满足该要求,Gulp软件包而不是Gulp Build也将产生VSIX。唯一真正的技巧是获得在测试环境中安装的VSIX名称。

const vsixName = fs.readdirSync(extensionDevelopmentPath)
    .filter(p => path.extname(p) === ".vsix")
    .sort((a, b) => a < b ? 1 : a > b ? -1 : 0)[0];

const launchArgs = [
    path.resolve(__dirname, '../../src/test/test-docs'),
    "--install-extension",
    vsixName
];

可能是一种混合方法;某些注册命令仅用于单位测试。这些可能会被垃圾以支持直接电话。

I just noticed this up the top of extension.test.ts

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';

That's not how my tests are written. They don't import the code and call it directly, they assume the extension is installed and active and they use registered commands. Some of these commands were added for no other reason than to allow fine grained unit tests.

The problem I describe in the question is due to the fact that the extension is not installed.

Discovering I can import from the extension doesn't solve all the problems. Some of my tests are strictly speaking integration tests. They need the extension to be installed and active.

To meet that requirement, gulp package rather than gulp build will also produce the VSIX. The only real trick is obtaining the VSIX name to install it in the test environment.

const vsixName = fs.readdirSync(extensionDevelopmentPath)
    .filter(p => path.extname(p) === ".vsix")
    .sort((a, b) => a < b ? 1 : a > b ? -1 : 0)[0];

const launchArgs = [
    path.resolve(__dirname, '../../src/test/test-docs'),
    "--install-extension",
    vsixName
];

A hybrid approach is possible; some of the registered commands exist only for use by unit tests. These could be junked in favour of direct calls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文