blob: f9369e6dc5ef41d7d961662a986c09f234bd0d79 [file] [log] [blame] [edit]
// 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 vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs/promises';
import { describe, it, before } from 'mocha';
import { expect } from 'chai';
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'));
// 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 () {
expect(registeredCommands).to.include.members(userCommands, 'registered commands (actual) should contain all package.json commands (expected)');
const nonInternalRegistered = registeredCommands.filter((cmd) => !cmd.startsWith('fuchsia.internal.'));
expect(userCommands).to.include.members(nonInternalRegistered, 'package.json commands (actual) should contain registered non-internal commands (expected)');
});
});