Run prettier plugin test in CI and mocha explorer, fix test bug (#570)
This commit is contained in:
Родитель
62da05403d
Коммит
d2658c5e33
|
@ -1,6 +1,6 @@
|
|||
import { spawn, spawnSync } from "child_process";
|
||||
import { statSync, readFileSync } from "fs";
|
||||
import { dirname, resolve } from "path";
|
||||
import { dirname, join, resolve } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
function read(filename) {
|
||||
|
@ -31,7 +31,11 @@ export function forEachProject(onEach) {
|
|||
|
||||
export function npmForEach(cmd, options) {
|
||||
forEachProject((name, location, project) => {
|
||||
// checks for the script first
|
||||
if (cmd === "test-official" && !project.scripts[cmd] && project.scripts["test"]) {
|
||||
const pj = join(location, "package.json");
|
||||
throw new Error(`${pj} has a 'test' script, but no 'test-official' script for CI.`);
|
||||
}
|
||||
|
||||
if (project.scripts[cmd] || cmd === "pack") {
|
||||
const args = cmd === "pack" ? [cmd] : ["run", cmd];
|
||||
run("npm", args, { cwd: location, ...options });
|
||||
|
|
|
@ -52,7 +52,7 @@ async function testScenario(name: string) {
|
|||
}
|
||||
}
|
||||
|
||||
describe("Format scenarios", () => {
|
||||
describe("adl: prettier formatter scenarios", () => {
|
||||
it("misc", async () => {
|
||||
await testScenario("misc.adl");
|
||||
});
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "rollup --config 2>&1 && npm run generate-third-party-notices",
|
||||
"test": "node ./test/smoke.js",
|
||||
"test": "mocha --timeout 5000 'test/**/*.js'",
|
||||
"test-official": "mocha --timeout 5000 --forbid-only 'test/**/*.js'",
|
||||
"generate-third-party-notices": "node ../../eng/scripts/generate-third-party-notices"
|
||||
},
|
||||
"author": "Microsoft Corporation",
|
||||
|
@ -19,6 +20,7 @@
|
|||
"@rollup/plugin-json": "~4.1.0",
|
||||
"@rollup/plugin-node-resolve": "~11.2.0",
|
||||
"@rollup/plugin-replace": "~2.4.2",
|
||||
"mocha": "~8.3.2",
|
||||
"rollup": "~2.41.4"
|
||||
},
|
||||
"files": [
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
// Simple smoke test verifying the plugin is able to be loaded via prettier.
|
||||
const prettier = require("prettier");
|
||||
const { strictEqual } = require("assert");
|
||||
const { resolve } = require("path");
|
||||
|
||||
const result = prettier.format("alias Foo = string", {
|
||||
parser: "adl",
|
||||
plugins: ["."],
|
||||
describe("prettier-plugin: smoke test", () => {
|
||||
it("loads and formats", () => {
|
||||
const result = prettier.format("alias Foo = string;", {
|
||||
parser: "adl",
|
||||
plugins: [resolve(__dirname, "..")],
|
||||
});
|
||||
strictEqual(result, "alias Foo = string;");
|
||||
});
|
||||
});
|
||||
|
||||
if (result !== "alias Foo = string;") {
|
||||
throw new Error("Failed to format as expeceted");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче