| // Copyright 2022 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| import * as assert from 'assert'; |
| import * as fs from 'fs/promises'; |
| import * as path from 'path'; |
| import * as vscode from 'vscode'; |
| |
| import { describe, it, before } from 'mocha'; |
| |
| describe('commands', function () { |
| let userCommands: string[]; |
| let registeredCommands: string[]; |
| before(async function () { |
| const packageDir = path.join(__dirname, '..'); |
| const packageJSON = JSON.parse(await fs.readFile(path.join(packageDir, 'package.json'), 'utf8')) as { |
| contributes: { |
| commands: { command: string }[]; |
| }; |
| }; |
| |
| // sort to make comparison easier |
| userCommands = packageJSON.contributes.commands |
| .map((cmd: { command: string }) => cmd.command) |
| .sort(); |
| registeredCommands = (await vscode.commands.getCommands(true /* filterInternal */)) |
| .filter(cmd => cmd.startsWith('fuchsia.')) |
| .sort(); |
| }); |
| |
| // two separate equalities to make the errors a bit clearer |
| |
| it('should be listed in both code and package.json (unless they are fuchsia.internal commands)', function () { |
| // registered commands (actual) should contain all package.json commands (expected) |
| for (const cmd of userCommands) { |
| assert.ok(registeredCommands.includes(cmd), `Missing expected command: ${cmd}`); |
| } |
| |
| // package.json commands (actual) should contain registered non-internal commands (expected) |
| const nonInternalRegistered = registeredCommands.filter(cmd => !cmd.startsWith('fuchsia.internal.')); |
| for (const cmd of nonInternalRegistered) { |
| assert.ok(userCommands.includes(cmd), `Unexpected registered command: ${cmd}`); |
| } |
| }); |
| }); |