chore: update * pin prettier version & format code
This commit is contained in:
parent
5d05f87768
commit
53d4062e52
18 changed files with 93 additions and 78 deletions
|
|
@ -7,7 +7,11 @@ import { promises as fs } from "fs";
|
|||
import * as path from "path";
|
||||
|
||||
import {
|
||||
npmCmd, runCommand, WEBSNACKS_BIN_PATH, WEBSNACKS_REPO_ROOT, withTempDir
|
||||
npmCmd,
|
||||
runCommand,
|
||||
WEBSNACKS_BIN_PATH,
|
||||
WEBSNACKS_REPO_ROOT,
|
||||
withTempDir,
|
||||
} from "../helpers/e2e";
|
||||
import { testSuite } from "../lib";
|
||||
|
||||
|
|
@ -35,7 +39,7 @@ testSuite("build command", ({ test }) => {
|
|||
}),
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
},
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(tempDirPath, "websnacks.ts"),
|
||||
|
|
@ -48,7 +52,7 @@ testSuite("build command", ({ test }) => {
|
|||
`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
},
|
||||
);
|
||||
const pagesPath = path.join(tempDirPath, "pages");
|
||||
await fs.mkdir(pagesPath);
|
||||
|
|
@ -60,7 +64,7 @@ testSuite("build command", ({ test }) => {
|
|||
`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
},
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(tempDirPath, "package.json"),
|
||||
|
|
@ -69,7 +73,7 @@ testSuite("build command", ({ test }) => {
|
|||
websnacks: `file:${WEBSNACKS_REPO_ROOT}`,
|
||||
},
|
||||
}),
|
||||
{ encoding: "utf8" }
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
await runCommand(npmCmd, ["install", "--silent"], {
|
||||
cwd: tempDirPath,
|
||||
|
|
@ -79,7 +83,7 @@ testSuite("build command", ({ test }) => {
|
|||
[WEBSNACKS_BIN_PATH, "-r", "ts-node/register", "build"],
|
||||
{
|
||||
cwd: tempDirPath,
|
||||
}
|
||||
},
|
||||
);
|
||||
await cmd.complete;
|
||||
});
|
||||
|
|
@ -108,7 +112,7 @@ testSuite("build command", ({ test }) => {
|
|||
}),
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
},
|
||||
);
|
||||
const pagesPath = path.join(tempDirPath, "pages");
|
||||
await fs.mkdir(pagesPath);
|
||||
|
|
@ -120,7 +124,7 @@ testSuite("build command", ({ test }) => {
|
|||
`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
},
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(tempDirPath, "package.json"),
|
||||
|
|
@ -129,7 +133,7 @@ testSuite("build command", ({ test }) => {
|
|||
websnacks: `file:${WEBSNACKS_REPO_ROOT}`,
|
||||
},
|
||||
}),
|
||||
{ encoding: "utf8" }
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
await runCommand(npmCmd, ["install", "--silent"], {
|
||||
cwd: tempDirPath,
|
||||
|
|
@ -139,7 +143,7 @@ testSuite("build command", ({ test }) => {
|
|||
[WEBSNACKS_BIN_PATH, "-r", "ts-node/register", "build"],
|
||||
{
|
||||
cwd: tempDirPath,
|
||||
}
|
||||
},
|
||||
);
|
||||
await cmd.complete;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,7 +7,12 @@ import { promises as fs } from "fs";
|
|||
import * as path from "path";
|
||||
|
||||
import {
|
||||
npmCmd, runCommand, wait, WEBSNACKS_BIN_PATH, WEBSNACKS_REPO_ROOT, withTempDir
|
||||
npmCmd,
|
||||
runCommand,
|
||||
wait,
|
||||
WEBSNACKS_BIN_PATH,
|
||||
WEBSNACKS_REPO_ROOT,
|
||||
withTempDir,
|
||||
} from "../helpers/e2e";
|
||||
import { testSuite } from "../lib";
|
||||
|
||||
|
|
@ -35,7 +40,7 @@ testSuite("dev command", ({ test, expect }) => {
|
|||
}),
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
},
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(tempDirPath, "websnacks.ts"),
|
||||
|
|
@ -48,7 +53,7 @@ testSuite("dev command", ({ test, expect }) => {
|
|||
`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
},
|
||||
);
|
||||
const pagesPath = path.join(tempDirPath, "pages");
|
||||
await fs.mkdir(pagesPath);
|
||||
|
|
@ -60,7 +65,7 @@ testSuite("dev command", ({ test, expect }) => {
|
|||
`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
},
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(tempDirPath, "package.json"),
|
||||
|
|
@ -69,7 +74,7 @@ testSuite("dev command", ({ test, expect }) => {
|
|||
websnacks: `file:${WEBSNACKS_REPO_ROOT}`,
|
||||
},
|
||||
}),
|
||||
{ encoding: "utf8" }
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
await runCommand(npmCmd, ["install", "--silent"], {
|
||||
cwd: tempDirPath,
|
||||
|
|
@ -79,7 +84,7 @@ testSuite("dev command", ({ test, expect }) => {
|
|||
[WEBSNACKS_BIN_PATH, "-r", "ts-node/register", "dev"],
|
||||
{
|
||||
cwd: tempDirPath,
|
||||
}
|
||||
},
|
||||
);
|
||||
// FIXME: This test is a bit brittle due to relying on timeouts.
|
||||
await wait(10_000);
|
||||
|
|
@ -112,7 +117,7 @@ testSuite("dev command", ({ test, expect }) => {
|
|||
}),
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
},
|
||||
);
|
||||
const pagesPath = path.join(tempDirPath, "pages");
|
||||
await fs.mkdir(pagesPath);
|
||||
|
|
@ -124,7 +129,7 @@ testSuite("dev command", ({ test, expect }) => {
|
|||
`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
},
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(tempDirPath, "package.json"),
|
||||
|
|
@ -133,7 +138,7 @@ testSuite("dev command", ({ test, expect }) => {
|
|||
websnacks: `file:${WEBSNACKS_REPO_ROOT}`,
|
||||
},
|
||||
}),
|
||||
{ encoding: "utf8" }
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
await runCommand(npmCmd, ["install", "--silent"], {
|
||||
cwd: tempDirPath,
|
||||
|
|
@ -143,7 +148,7 @@ testSuite("dev command", ({ test, expect }) => {
|
|||
[WEBSNACKS_BIN_PATH, "-r", "ts-node/register", "dev"],
|
||||
{
|
||||
cwd: tempDirPath,
|
||||
}
|
||||
},
|
||||
);
|
||||
// FIXME: This test is a bit brittle due to relying on timeouts.
|
||||
await wait(10_000);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ const TEMP_PATH = path.resolve(__dirname, "..", "..", ".temp");
|
|||
* directory path as its only argument.
|
||||
*/
|
||||
export const withTempDir = async (
|
||||
op: (tempDirPath: string) => Promise<void> | void
|
||||
op: (tempDirPath: string) => Promise<void> | void,
|
||||
): Promise<void> => {
|
||||
await fs.mkdir(TEMP_PATH, { recursive: true });
|
||||
const tempDirPath = await fs.mkdtemp(`${TEMP_PATH}/`);
|
||||
|
|
@ -57,7 +57,7 @@ export const WEBSNACKS_REPO_ROOT = path.resolve(__dirname, "..", "..");
|
|||
export const WEBSNACKS_BIN_PATH = path.join(
|
||||
WEBSNACKS_REPO_ROOT,
|
||||
"bin",
|
||||
"websnacks.js"
|
||||
"websnacks.js",
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
@ -113,7 +113,7 @@ const DEFAULT_CLI_OPTIONS = {
|
|||
export const runCommand = (
|
||||
command: string,
|
||||
args: string[] = [],
|
||||
options?: CliOptions
|
||||
options?: CliOptions,
|
||||
): AsyncCommand => {
|
||||
const optionsWithDefaults = { ...DEFAULT_CLI_OPTIONS, ...options };
|
||||
const process = spawn(command, args, {
|
||||
|
|
@ -138,8 +138,8 @@ export const runCommand = (
|
|||
process.kill();
|
||||
reject(
|
||||
new Error(
|
||||
`max timeout of ${optionsWithDefaults.timeoutMs}ms reached`
|
||||
)
|
||||
`max timeout of ${optionsWithDefaults.timeoutMs}ms reached`,
|
||||
),
|
||||
);
|
||||
}, optionsWithDefaults.timeoutMs);
|
||||
process.on("exit", (code) => {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class ExpectError extends Error {
|
|||
super(
|
||||
`${reason}\n` +
|
||||
`\texpected: ${displayValue(expected)}\n` +
|
||||
`\tactual : ${displayValue(actual)}`
|
||||
`\tactual : ${displayValue(actual)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ export class Expect<T> {
|
|||
throw new ExpectError(
|
||||
`value does not equal expected`,
|
||||
expected,
|
||||
this.value
|
||||
this.value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ export class StringExpect extends Expect<string> {
|
|||
throw new ExpectError(
|
||||
`value does not match expected pattern`,
|
||||
pattern,
|
||||
this.value
|
||||
this.value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ export class StringExpect extends Expect<string> {
|
|||
throw new ExpectError(
|
||||
`value does not start with expected prefix`,
|
||||
prefix,
|
||||
this.value
|
||||
this.value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ export class StringExpect extends Expect<string> {
|
|||
throw new ExpectError(
|
||||
`value does not end with expected suffix`,
|
||||
suffix,
|
||||
this.value
|
||||
this.value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -138,14 +138,14 @@ export class FunctionExpect<T> extends Expect<() => T> {
|
|||
throw new ExpectError(
|
||||
`function threw non-Error value`,
|
||||
pattern,
|
||||
error
|
||||
error,
|
||||
);
|
||||
}
|
||||
if (!matches(error.message, pattern)) {
|
||||
throw new ExpectError(
|
||||
`thrown Error's message does not match pattern`,
|
||||
pattern,
|
||||
error.message
|
||||
error.message,
|
||||
);
|
||||
}
|
||||
return;
|
||||
|
|
@ -153,7 +153,7 @@ export class FunctionExpect<T> extends Expect<() => T> {
|
|||
throw new ExpectError(
|
||||
`function did not throw expected error`,
|
||||
pattern,
|
||||
null
|
||||
null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ const runTest = async (test: Test): Promise<TestResult> => {
|
|||
error instanceof Error
|
||||
? error
|
||||
: new Error(
|
||||
`threw non-error object: ${displayValue(error)}`
|
||||
`threw non-error object: ${displayValue(error)}`,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ export interface TestSuiteContext {
|
|||
*/
|
||||
export const testSuite = (
|
||||
suiteName: string,
|
||||
def: (ctx: TestSuiteContext) => void
|
||||
def: (ctx: TestSuiteContext) => void,
|
||||
): void => {
|
||||
const tests: Test[] = [];
|
||||
const test = (name: string, runTest: () => void | Promise<void>): void => {
|
||||
|
|
@ -104,14 +104,14 @@ export const testSuite = (
|
|||
if (testResult.result === "fail") {
|
||||
console.error(
|
||||
`[TEST FAILURE] "${suiteName}": "${testResult.testName}": ` +
|
||||
`${testResult.error.stack}\n`
|
||||
`${testResult.error.stack}\n`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
passed += 1;
|
||||
}
|
||||
console.info(
|
||||
`[TEST] suite "${suiteName}": ${passed} of ${tests.length} succeeded\n\n`
|
||||
`[TEST] suite "${suiteName}": ${passed} of ${tests.length} succeeded\n\n`,
|
||||
);
|
||||
if (passed < tests.length) {
|
||||
process.exitCode = 1;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ const areArraysEqual = <T>(a: T[], b: T[]): boolean => {
|
|||
|
||||
const areObjectsEqual = <T extends Record<string, unknown>>(
|
||||
a: T,
|
||||
b: T
|
||||
b: T,
|
||||
): boolean => {
|
||||
const aKeys = Object.keys(a) as Array<keyof T>;
|
||||
const bKeys = Object.keys(b) as Array<keyof T>;
|
||||
|
|
@ -67,7 +67,7 @@ export const areEqual = <T>(a: T, b: T): boolean => {
|
|||
if (typeof a === "object" && typeof b === "object") {
|
||||
return areObjectsEqual(
|
||||
a as Record<string, unknown>,
|
||||
b as Record<string, unknown>
|
||||
b as Record<string, unknown>,
|
||||
);
|
||||
}
|
||||
return a === b;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { testSuite } from "../lib";
|
|||
testSuite("renderPage", ({ test, expect }) => {
|
||||
test("throws an Error when root elem is not html tag", () => {
|
||||
expect(() => renderPage(<div />)).toThrowErrorMatching(
|
||||
"attempted to render page with non-HTML root element div"
|
||||
"attempted to render page with non-HTML root element div",
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -21,10 +21,10 @@ testSuite("renderPage", ({ test, expect }) => {
|
|||
|
||||
test("escapes HTML in tag names", () => {
|
||||
const html = renderPage(
|
||||
<html>{createElement("div></div", null)}</html>
|
||||
<html>{createElement("div></div", null)}</html>,
|
||||
);
|
||||
expect(html).toEqual(
|
||||
"<!DOCTYPE html><html><div></div></div></div></html>"
|
||||
"<!DOCTYPE html><html><div></div></div></div></html>",
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -32,10 +32,10 @@ testSuite("renderPage", ({ test, expect }) => {
|
|||
const html = renderPage(
|
||||
<html>
|
||||
<div className="test" id="1" />
|
||||
</html>
|
||||
</html>,
|
||||
);
|
||||
expect(html).toEqual(
|
||||
'<!DOCTYPE html><html><div class="test" id="1"></div></html>'
|
||||
'<!DOCTYPE html><html><div class="test" id="1"></div></html>',
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -48,17 +48,17 @@ testSuite("renderPage", ({ test, expect }) => {
|
|||
<body>
|
||||
<div />
|
||||
</body>
|
||||
</html>
|
||||
</html>,
|
||||
);
|
||||
expect(html).toEqual(
|
||||
"<!DOCTYPE html><html><head><title></title></head><body><div></div></body></html>"
|
||||
"<!DOCTYPE html><html><head><title></title></head><body><div></div></body></html>",
|
||||
);
|
||||
});
|
||||
|
||||
test("renders text nodes", () => {
|
||||
const html = renderPage(<html>There are three lights!</html>);
|
||||
expect(html).toEqual(
|
||||
"<!DOCTYPE html><html>There are three lights!</html>"
|
||||
"<!DOCTYPE html><html>There are three lights!</html>",
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -80,10 +80,10 @@ testSuite("renderPage", ({ test, expect }) => {
|
|||
<Light lightN={lightN} />
|
||||
))}{" "}
|
||||
lights!
|
||||
</html>
|
||||
</html>,
|
||||
);
|
||||
expect(html).toEqual(
|
||||
"<!DOCTYPE html><html>There are <div>1</div><div>2</div><div>3</div> lights!</html>"
|
||||
"<!DOCTYPE html><html>There are <div>1</div><div>2</div><div>3</div> lights!</html>",
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -97,10 +97,10 @@ testSuite("renderPage", ({ test, expect }) => {
|
|||
const html = renderPage(
|
||||
<html>
|
||||
There are <Light nLights={3} />!
|
||||
</html>
|
||||
</html>,
|
||||
);
|
||||
expect(html).toEqual(
|
||||
"<!DOCTYPE html><html>There are <div>3 lights</div>!</html>"
|
||||
"<!DOCTYPE html><html>There are <div>3 lights</div>!</html>",
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -111,10 +111,10 @@ testSuite("renderPage", ({ test, expect }) => {
|
|||
<div>test of</div>
|
||||
<div>fragments</div>
|
||||
</Fragment>
|
||||
</html>
|
||||
</html>,
|
||||
);
|
||||
expect(html).toEqual(
|
||||
"<!DOCTYPE html><html><div>test of</div><div>fragments</div></html>"
|
||||
"<!DOCTYPE html><html><div>test of</div><div>fragments</div></html>",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue