Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
chore: add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Sep 9, 2022
1 parent 855609d commit 54488e3
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 153 deletions.
225 changes: 112 additions & 113 deletions npm/rome/tests/daemon/formatContent.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,116 +6,115 @@ import { fileURLToPath } from "url";
const target = process.env.CI ? "target/release/rome" : "target/debug/rome";

describe("Rome Deamon formatter", () => {

it("should format content", async () => {
const command = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary: command,
});
let result = await rome.formatContent("function f () { }", {
filePath: "example.js",
});

expect(result.content).toEqual("function f() {}\n");
expect(result.diagnostics).toEqual([]);
});

it("should not format and have diagnostics", async () => {
const command = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary: command,
});

let content = "function () { }";
let result = await rome.formatContent(content, {
filePath: "example.js",
});

expect(result.content).toEqual(content);
expect(result.diagnostics).toHaveLength(1);
expect(result.diagnostics[0].title[0].content).toContain(
"expected a name for the function in a function declaration, but found none",
);
expect(result.diagnostics).toMatchSnapshot("syntax error");
});

it("should format content in debug mode", async () => {
const command = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary: command,
});

let result = await rome.formatContent("function f() {}", {
filePath: "example.js",
debug: true,
});

expect(result.content).toEqual("function f() {}\n");
expect(result.diagnostics).toEqual([]);
expect(result.ir).toMatchInlineSnapshot(
'"[\\"function\\", \\" \\", \\"f\\", group([\\"(\\", \\")\\"]), \\" \\", \\"{\\", \\"}\\", hard_line_break]"',
);
});

it("should not format content with range", async () => {
const command = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary: command,
});
let result = await rome.formatContent("let a ; function g () { }", {
filePath: "file.js",
range: [20, 25],
});

expect(result.content).toEqual("function g() {}");
expect(result.diagnostics).toEqual([]);
});

it("should not format content with range in debug mode", async () => {
const command = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary: command,
});
let result = await rome.formatContent("let a ; function g () { }", {
filePath: "file.js",
range: [20, 25],
debug: true,
});

expect(result.content).toEqual("function g() {}");
expect(result.diagnostics).toEqual([]);
expect(result.ir).toMatchInlineSnapshot(
`
it("should format content", async () => {
const command = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary: command,
});
let result = await rome.formatContent("function f () { }", {
filePath: "example.js",
});

expect(result.content).toEqual("function f() {}\n");
expect(result.diagnostics).toEqual([]);
});

it("should not format and have diagnostics", async () => {
const command = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary: command,
});

let content = "function () { }";
let result = await rome.formatContent(content, {
filePath: "example.js",
});

expect(result.content).toEqual(content);
expect(result.diagnostics).toHaveLength(1);
expect(result.diagnostics[0].title[0].content).toContain(
"expected a name for the function in a function declaration, but found none",
);
expect(result.diagnostics).toMatchSnapshot("syntax error");
});

it("should format content in debug mode", async () => {
const command = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary: command,
});

let result = await rome.formatContent("function f() {}", {
filePath: "example.js",
debug: true,
});

expect(result.content).toEqual("function f() {}\n");
expect(result.diagnostics).toEqual([]);
expect(result.ir).toMatchInlineSnapshot(
'"[\\"function\\", \\" \\", \\"f\\", group([\\"(\\", \\")\\"]), \\" \\", \\"{\\", \\"}\\", hard_line_break]"',
);
});

it("should not format content with range", async () => {
const command = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary: command,
});
let result = await rome.formatContent("let a ; function g () { }", {
filePath: "file.js",
range: [20, 25],
});

expect(result.content).toEqual("function g() {}");
expect(result.diagnostics).toEqual([]);
});

it("should not format content with range in debug mode", async () => {
const command = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary: command,
});
let result = await rome.formatContent("let a ; function g () { }", {
filePath: "file.js",
range: [20, 25],
debug: true,
});

expect(result.content).toEqual("function g() {}");
expect(result.diagnostics).toEqual([]);
expect(result.ir).toMatchInlineSnapshot(
`
"[
group([\\"let\\", \\" \\", \\"a\\"]),
\\";\\",
Expand All @@ -130,6 +129,6 @@ describe("Rome Deamon formatter", () => {
hard_line_break
]"
`,
);
});
});
);
});
}, 1500);
80 changes: 40 additions & 40 deletions npm/rome/tests/daemon/formatFiles.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,44 @@ import { fileURLToPath } from "url";
const target = process.env.CI ? "target/release/rome" : "target/debug/rome";

describe("Rome Deamon formatter", () => {
it("should not format files", async () => {
const pathToBinary = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

console.log(pathToBinary);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary,
});

let result = await rome.formatFiles(["./path/to/file.js"]);

expect(result.content).toEqual("");
expect(result.diagnostics).toEqual([]);
});

it("should not format files in debug mode", async () => {
const pathToBinary = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary,
});

let result = await rome.formatFiles(["./path/to/file.js"], {
debug: true,
});

expect(result.content).toEqual("");
expect(result.diagnostics).toEqual([]);
expect(result.ir).toEqual("");
});
it("should not format files", async () => {
const pathToBinary = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

console.log(pathToBinary);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary,
});

let result = await rome.formatFiles(["./path/to/file.js"]);

expect(result.content).toEqual("");
expect(result.diagnostics).toEqual([]);
});

it("should not format files in debug mode", async () => {
const pathToBinary = resolve(
fileURLToPath(import.meta.url),
"../../../../..",
target,
);

const rome = await Rome.create({
backendKind: BackendKind.DAEMON,
pathToBinary,
});

let result = await rome.formatFiles(["./path/to/file.js"], {
debug: true,
});

expect(result.content).toEqual("");
expect(result.diagnostics).toEqual([]);
expect(result.ir).toEqual("");
});
});

0 comments on commit 54488e3

Please sign in to comment.