Add TestDiagnosticAdvice - fixes
MODIFY
packages/@romejs-runtime/rome/test.ts
packages/@romejs-runtime/rome/test.ts
* LICENSE file in the root directory of this source tree.
*/
+import {JSONPropertyValue} from './types';
+
export type AsyncFunc = () => undefined | Promise<void>;
export type SyncThrower = () => void;
@@ -16,9 +18,40 @@ export type TestSnapshotOptions = {
language?: string;
};
+// These diagnostics are subsets of the official diagnostics
+// We can potentially normalize these and ensure backwards compatibility with the official diagnostics
+
+export type TestDiagnosticLogCategory = 'none' | 'info' | 'warn' | 'error';
+
+export type TestDiagnosticAdviceInspect = {
+ type: 'inspect';
+ data: JSONPropertyValue;
+};
+
+export type TestDiagnosticAdviceList = {
+ type: 'list';
+ list: Array<string>;
+};
+
+export type TestDiagnosticAdviceCode = {
+ type: 'code';
+ code: string;
+};
+
+export type TestDiagnosticAdviceLog = {
+ type: 'log';
+ category: TestDiagnosticLogCategory;
+ text: string;
+};
+
+export type TestDiagnosticAdviceItem =
+ | TestDiagnosticAdviceInspect
+ | TestDiagnosticAdviceCode
+ | TestDiagnosticAdviceLog
+ | TestDiagnosticAdviceList;
+
export interface TestHelper {
- // TODO this should be DiagnosticAdviceItem
- addToAdvice(item: unknown): void;
+ addToAdvice(item: TestDiagnosticAdviceItem): void;
clearAdvice(): void;
onTeardown(callback: AsyncFunc): void;
clearTimeout(): void;

ADD
packages/@romejs-runtime/rome/types.ts
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+// These are copied from packages/@romejs/codec-json/types.ts
+export type JSONValue =
+ | null
+ | string
+ | number
+ | boolean
+ | JSONObject
+ | JSONArray;
+
+export type JSONPropertyValue = undefined | void | JSONValue;
+
+export type JSONObject = {
+ [x: string]: JSONPropertyValue;
+};
+
+export type JSONArray = Array<JSONValue>;

MODIFY
packages/@romejs/core/test-worker/TestAPI.ts
packages/@romejs/core/test-worker/TestAPI.ts
* LICENSE file in the root directory of this source tree.
*/
-import {
- DiagnosticAdvice,
- DiagnosticAdviceItem,
- getErrorStackAdvice,
-} from '@romejs/diagnostics';
+import {DiagnosticAdvice, getErrorStackAdvice} from '@romejs/diagnostics';
import SnapshotManager from './SnapshotManager';
import {TestRunnerOptions} from '../master/testing/types';
import {Event} from '@romejs/events';
@@ -22,10 +18,10 @@ import {
AsyncFunc,
ExpectedError,
SyncThrower,
+ TestDiagnosticAdviceItem,
TestHelper,
TestSnapshotOptions,
} from '@romejs-runtime/rome/test';
-
function formatExpectedError(expected: ExpectedError): string {
if (typeof expected === 'string') {
return JSON.stringify(expected);
@@ -215,7 +211,7 @@ export default class TestAPI implements TestHelper {
return advice;
}
- addToAdvice(item: DiagnosticAdviceItem): void {
+ addToAdvice(item: TestDiagnosticAdviceItem): void {
this.advice.push(item);
}

MODIFY
packages/@romejs/js-compiler/lint/testHelpers.ts
packages/@romejs/js-compiler/lint/testHelpers.ts
@@ -38,7 +38,7 @@ export async function testLint(
t.addToAdvice({
type: 'log',
category: 'info',
- message: 'Lint options',
+ text: 'Lint options',
});
t.addToAdvice({
@@ -53,7 +53,7 @@ export async function testLint(
t.addToAdvice({
type: 'log',
category: 'info',
- message: 'Input',
+ text: 'Input',
});
t.addToAdvice({

MODIFY
packages/@romejs/js-formatter/index.test.ts
packages/@romejs/js-formatter/index.test.ts
@@ -57,7 +57,7 @@ const promise = createFixtureTests(async (fixture, t) => {
t.addToAdvice({
type: 'log',
category: 'info',
- message: 'Fomat options',
+ text: 'Fomat options',
});
t.addToAdvice({

MODIFY
packages/@romejs/js-parser/index.test.ts
packages/@romejs/js-parser/index.test.ts
@@ -45,7 +45,7 @@ const promise = createFixtureTests(async (fixture, t) => {
t.addToAdvice({
type: 'log',
category: 'info',
- message: 'Parser options',
+ text: 'Parser options',
});
t.addToAdvice({

MODIFY
packages/@romejs/path/index.test.ts
packages/@romejs/path/index.test.ts
@@ -58,7 +58,7 @@ for (let i = 0; i < relativeTests.length; i++) {
t.addToAdvice({
type: 'log',
category: 'info',
- message: 'Metadata',
+ text: 'Metadata',
});
const relative = createAbsoluteFilePath(absolute).relative(arg);

MODIFY
packages/@romejs/test-helpers/index.ts
packages/@romejs/test-helpers/index.ts
@@ -163,7 +163,7 @@ export async function createFixtureTests(
t.addToAdvice({
type: 'log',
category: 'info',
- message: 'Fixture options',
+ text: 'Fixture options',
});
t.addToAdvice({
@@ -174,7 +174,7 @@ export async function createFixtureTests(
t.addToAdvice({
type: 'log',
category: 'info',
- message: 'Fixture files',
+ text: 'Fixture files',
});
t.addToAdvice({

Add TestDiagnosticAdvice - fixes #325