Allow updating fixtures output with --update-snapshots
MODIFY
packages/@romejs-runtime/rome/test.ts
packages/@romejs-runtime/rome/test.ts
* LICENSE file in the root directory of this source tree.
*/
+import {TestRunnerOptions} from '@romejs/core/master/testing/types';
+
export type AsyncFunc = () => undefined | Promise<void>;
export type SyncThrower = () => void;
@@ -39,6 +41,7 @@ export interface TestHelper {
snapshot(expected: unknown, message?: string): string;
snapshotNamed(name: string, expected: unknown, message?: string): string;
getSnapshot(snapshotName: string): unknown;
+ getOptions(): TestRunnerOptions;
}
export type TestName = string | Array<string>;

MODIFY
packages/@romejs/core/test-worker/TestAPI.ts
packages/@romejs/core/test-worker/TestAPI.ts
@@ -441,6 +441,10 @@ export default class TestAPI implements TestHelper {
return this.snapshotManager.get(this.testName, snapshotName);
}
+ getOptions(): TestRunnerOptions {
+ return this.options;
+ }
+
_snapshotNamed(
name: string,
expected: unknown,

MODIFY
packages/@romejs/js-parser/index.test.ts
packages/@romejs/js-parser/index.test.ts
@@ -138,7 +138,8 @@ const promise = createFixtureTests(
}
// If we have an output then compare it with the parsed input
- if (outputContent !== undefined) {
+ const runnerOptions = t.getOptions();
+ if (outputContent !== undefined && !runnerOptions.updateSnapshots) {
t.is(prettyFormat(ast), outputContent.trim());
}
@@ -154,7 +155,7 @@ const promise = createFixtureTests(
return;
}
- if (outputContent === undefined) {
+ if (outputContent === undefined || runnerOptions.updateSnapshots) {
// If we didn't expect an error to be thrown and we have no expected output AST
// then we should write it

Allow updating fixtures output with --update-snapshots