From 7df291726a945402b2910f25d59ed9588a23b74d Mon Sep 17 00:00:00 2001 From: Ian Clanton-Thuon Date: Tue, 14 Jul 2020 17:56:47 -0700 Subject: [PATCH] Only update snapshots in non-production mode. --- apps/heft/src/cli/actions/TestAction.ts | 4 +++- apps/heft/src/plugins/JestPlugin/JestPlugin.ts | 13 +++++++++++-- common/reviews/api/heft.api.md | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/heft/src/cli/actions/TestAction.ts b/apps/heft/src/cli/actions/TestAction.ts index 094504d3ca8..1ae603ea4c7 100644 --- a/apps/heft/src/cli/actions/TestAction.ts +++ b/apps/heft/src/cli/actions/TestAction.ts @@ -20,6 +20,7 @@ export class TestHooks extends ActionHooksBase { */ export interface ITestActionProperties { watchMode: boolean; + productionFlag: boolean; } /** @@ -60,7 +61,8 @@ export class TestAction extends BuildAction { const testActionContext: ITestActionContext = { hooks: new TestHooks(), properties: { - watchMode: buildActionContext.properties.watchMode + watchMode: buildActionContext.properties.watchMode, + productionFlag: buildActionContext.properties.productionFlag } }; const shouldBuild: boolean = !this._noBuildFlag.value; diff --git a/apps/heft/src/plugins/JestPlugin/JestPlugin.ts b/apps/heft/src/plugins/JestPlugin/JestPlugin.ts index 7616dfde3e7..9a59af73edb 100644 --- a/apps/heft/src/plugins/JestPlugin/JestPlugin.ts +++ b/apps/heft/src/plugins/JestPlugin/JestPlugin.ts @@ -21,13 +21,21 @@ export class JestPlugin implements IHeftPlugin { if (FileSystem.exists(path.join(heftConfiguration.buildFolder, JEST_CONFIGURATION_LOCATION))) { heftSession.hooks.test.tap(PLUGIN_NAME, (test: ITestActionContext) => { test.hooks.run.tapPromise(PLUGIN_NAME, async () => { - await this._runJestAsync(heftConfiguration, test.properties.watchMode); + await this._runJestAsync( + heftConfiguration, + test.properties.watchMode, + test.properties.productionFlag + ); }); }); } } - private async _runJestAsync(heftConfiguration: HeftConfiguration, watchMode: boolean): Promise { + private async _runJestAsync( + heftConfiguration: HeftConfiguration, + watchMode: boolean, + production: boolean + ): Promise { const buildFolder: string = heftConfiguration.buildFolder; const reporterOptions: IHeftJestReporterOptions = { heftConfiguration }; const { results: jestResults } = await runCLI( @@ -36,6 +44,7 @@ export class JestPlugin implements IHeftPlugin { config: JEST_CONFIGURATION_LOCATION, reporters: [[path.resolve(__dirname, 'HeftJestReporter.js'), reporterOptions]], cacheDirectory: path.join(heftConfiguration.buildCacheFolder, 'jest-cache'), + updateSnapshot: !production, listTests: false, rootDir: buildFolder, diff --git a/common/reviews/api/heft.api.md b/common/reviews/api/heft.api.md index ce2fcae5947..0fce7b76847 100644 --- a/common/reviews/api/heft.api.md +++ b/common/reviews/api/heft.api.md @@ -292,6 +292,8 @@ export interface ITestActionContext extends IActionContext