diff --git a/src/browser/cdp/selectivity/index.ts b/src/browser/cdp/selectivity/index.ts index d0110866c..0c0b176ba 100644 --- a/src/browser/cdp/selectivity/index.ts +++ b/src/browser/cdp/selectivity/index.ts @@ -10,6 +10,7 @@ import { getCollectedTestplaneDependencies } from "./testplane-selectivity"; import { getHashReader } from "./hash-reader"; import type { Config } from "../../../config"; import { MasterEvents } from "../../../events"; +import { selectivityShouldWrite } from "./modes"; type StopSelectivityFn = (test: Test, shouldWrite: boolean) => Promise; @@ -24,7 +25,7 @@ export const updateSelectivityHashes = async (config: Config): Promise => const browserConfig = config.forBrowser(browserId); const { enabled, testDependenciesPath, compression, disableSelectivityPatterns } = browserConfig.selectivity; - if (!enabled) { + if (!selectivityShouldWrite(enabled)) { continue; } @@ -51,7 +52,7 @@ export const startSelectivity = async (browser: ExistingBrowser): Promise Promise.resolve(); } diff --git a/src/browser/cdp/selectivity/modes.ts b/src/browser/cdp/selectivity/modes.ts new file mode 100644 index 000000000..9d9b8edf7 --- /dev/null +++ b/src/browser/cdp/selectivity/modes.ts @@ -0,0 +1,7 @@ +import { SelectivityMode, type SelectivityModeValue } from "../../../config/types"; + +export const selectivityIsDisabled = (mode: SelectivityModeValue): boolean => mode === SelectivityMode.Disabled; +export const selectivityShouldWrite = (mode: SelectivityModeValue): boolean => + mode === SelectivityMode.Enabled || mode === SelectivityMode.WriteOnly; +export const selectivityShouldRead = (mode: SelectivityModeValue): boolean => + mode === SelectivityMode.Enabled || mode === SelectivityMode.ReadOnly; diff --git a/src/browser/cdp/selectivity/runner.ts b/src/browser/cdp/selectivity/runner.ts index 5e1b22dbf..f956ca30c 100644 --- a/src/browser/cdp/selectivity/runner.ts +++ b/src/browser/cdp/selectivity/runner.ts @@ -9,11 +9,12 @@ import type { Test, TestDepsContext, TestDepsData } from "../../../types"; import { MasterEvents } from "../../../events"; import { getHashWriter } from "./hash-writer"; import { getTestDependenciesReader } from "./test-dependencies-reader"; +import { selectivityShouldRead } from "./modes"; /** Called at the start of testplane run per each browser */ const shouldDisableBrowserSelectivity = _.memoize( async (config: BrowserConfig, browserId: string): Promise => { - if (!config.selectivity.enabled) { + if (!selectivityShouldRead(config.selectivity.enabled)) { return true; } @@ -60,8 +61,9 @@ const shouldDisableBrowserSelectivity = _.memoize( }, config => { const { enabled, testDependenciesPath, compression, disableSelectivityPatterns } = config.selectivity; - return enabled - ? enabled + "#" + testDependenciesPath + "#" + compression + "#" + disableSelectivityPatterns.join("#") + + return selectivityShouldRead(enabled) + ? testDependenciesPath + "#" + compression + "#" + disableSelectivityPatterns.join("#") : ""; }, ); @@ -70,7 +72,7 @@ const shouldDisableTestBySelectivity = _.memoize( async (config: BrowserConfig, test: Test): Promise => { const { enabled, testDependenciesPath, compression } = config.selectivity; - if (!enabled) { + if (!selectivityShouldRead(enabled)) { return false; } @@ -99,7 +101,7 @@ const shouldDisableTestBySelectivity = _.memoize( (config, test) => { const { enabled, testDependenciesPath, compression } = config.selectivity; - return enabled ? enabled + "#" + testDependenciesPath + "#" + compression + "#" + test.id : ""; + return selectivityShouldRead(enabled) ? testDependenciesPath + "#" + compression + "#" + test.id : ""; }, ); @@ -157,11 +159,11 @@ export class SelectivityRunner { startTestCheckToRun(test: Test, browserId: string): void { const browserConfig = this._config.forBrowser(browserId); - const isSelectivityEnabledForBrowser = browserConfig.selectivity.enabled; + const shouldSelectivelySkipTests = selectivityShouldRead(browserConfig.selectivity.enabled); // If selectivity is disabled for browser // If test is disabled on its own (e.g plugin testplane/chunks) we dont waste our time calculating the deps. - if (!isSelectivityEnabledForBrowser || this._opts?.shouldDisableSelectivity || test.disabled) { + if (!shouldSelectivelySkipTests || this._opts?.shouldDisableSelectivity || test.disabled) { this._testsToRun.push([test, browserId]); return; } @@ -197,6 +199,10 @@ export class SelectivityRunner { shouldDisableBrowserSelectivity.cache.clear?.(); shouldDisableTestBySelectivity.cache.clear?.(); - getHashReader(this._config.selectivity.testDependenciesPath, this._config.selectivity.compression).clearCache(); + this._config.getBrowserIds().forEach(browserId => { + const { selectivity } = this._config.forBrowser(browserId); + + getHashReader(selectivity.testDependenciesPath, selectivity.compression).clearCache(); + }); } } diff --git a/src/config/types.ts b/src/config/types.ts index 0fcd03d08..74fd5618e 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -268,16 +268,29 @@ type ReadinessProbeObj = { type ReadinessProbe = ReadinessProbeFn | ReadinessProbeObj; export enum TimeTravelMode { - // Record and save all test runs + /** @description Record and save all test runs */ On = "on", - // Do not record any test runs + /** @description Do not record any test runs */ Off = "off", - // Record and save all retries + /** @description Record and save all retries */ RetriesOnly = "retries-only", - // Record all test runs, but save only last failed run + /** @description Record all test runs, but save only last failed run */ LastFailedRun = "last-failed-run", } +export const SelectivityMode = { + /** @description Completely disables Testplane selectivity */ + Disabled: false, + /** @description Skips running unchanged tests, does not update selectivity state after successful run */ + ReadOnly: "read-only", + /** @description Runs unchanged tests, updates selectivity state after successful run */ + WriteOnly: "write-only", + /** @description Skips running unchanged tests, updates selectivity state after successful run */ + Enabled: true, +} as const; + +export type SelectivityModeValue = (typeof SelectivityMode)[keyof typeof SelectivityMode]; + export interface TimeTravelConfig { mode: TimeTravelMode; } @@ -392,7 +405,7 @@ export interface CommonConfig { }; selectivity: { - enabled: boolean; + enabled: SelectivityModeValue; sourceRoot: string; testDependenciesPath: string; compression: SelectivityCompressionType; diff --git a/src/config/utils.ts b/src/config/utils.ts index c5ade4ad1..11f92bc9e 100644 --- a/src/config/utils.ts +++ b/src/config/utils.ts @@ -1,5 +1,5 @@ import _ from "lodash"; -import { ConfigParsed } from "./types"; +import { ConfigParsed, SelectivityMode, SelectivityModeValue } from "./types"; type ValueType = "string" | "number" | "boolean" | "object" | "undefined" | "function"; @@ -100,16 +100,21 @@ export const addUserAgentToArgs = (config: ConfigParsed): ConfigParsed => { return config; }; -export const extractSelectivityEnabledEnvVariable = (envPrefixes: string[] = []): { enabled?: boolean } => { +export const extractSelectivityEnabledEnvVariable = ( + envPrefixes: string[] = [], +): { enabled?: SelectivityModeValue } => { for (const envPrefix of envPrefixes) { const envName = envPrefix + "selectivity_enabled"; - if (process.env[envName] === String(true)) { - return { enabled: true }; - } - - if (process.env[envName] === String(false)) { - return { enabled: false }; + switch (process.env[envName]) { + case String(SelectivityMode.Enabled): + return { enabled: SelectivityMode.Enabled }; + case String(SelectivityMode.Disabled): + return { enabled: SelectivityMode.Disabled }; + case String(SelectivityMode.ReadOnly): + return { enabled: SelectivityMode.ReadOnly }; + case String(SelectivityMode.WriteOnly): + return { enabled: SelectivityMode.WriteOnly }; } } diff --git a/src/worker/runner/index.js b/src/worker/runner/index.js index a612085a2..ad6009d2a 100644 --- a/src/worker/runner/index.js +++ b/src/worker/runner/index.js @@ -13,6 +13,7 @@ const { } = require("../../browser/cdp/selectivity/testplane-selectivity"); const ipc = require("../../utils/ipc"); const { TEST_ASSIGNED_TO_WORKER } = require("../../constants/process-messages"); +const { selectivityShouldWrite } = require("../../browser/cdp/selectivity/modes"); module.exports = class Runner extends AsyncEmitter { static create(config) { @@ -55,13 +56,14 @@ module.exports = class Runner extends AsyncEmitter { attempt, }); - const selectivityEnabled = config.selectivity && config.selectivity.enabled && isRunInNodeJsEnv(this._config); + const shouldRecordSelectivityDeps = + config.selectivity && selectivityShouldWrite(config.selectivity.enabled) && isRunInNodeJsEnv(this._config); const prepareParseAndRun = async () => { runner.prepareBrowser({ sessionId, sessionCaps, sessionOpts, state }); const readTestsFn = () => this._testParser.parse({ file, browserId }); - const tests = selectivityEnabled + const tests = shouldRecordSelectivityDeps ? await readTestFileWithTestplaneDependenciesCollecting(file, readTestsFn) : await readTestsFn(); @@ -72,6 +74,8 @@ module.exports = class Runner extends AsyncEmitter { return runner.run(); }; - return selectivityEnabled ? runWithTestplaneDependenciesCollecting(prepareParseAndRun) : prepareParseAndRun(); + return shouldRecordSelectivityDeps + ? runWithTestplaneDependenciesCollecting(prepareParseAndRun) + : prepareParseAndRun(); } }; diff --git a/test/src/browser/cdp/selectivity/hash-reader.ts b/test/src/browser/cdp/selectivity/hash-reader.ts index a49023055..5162f4c09 100644 --- a/test/src/browser/cdp/selectivity/hash-reader.ts +++ b/test/src/browser/cdp/selectivity/hash-reader.ts @@ -136,7 +136,6 @@ describe("CDP/Selectivity/HashReader", () => { const result = reader.patternHasChanged(pattern); assert.isRejected(result, /Couldn't find files by disableSelectivityPattern/); - assert.calledWith(hashProviderMock.calculateForPattern, pattern); }); }); diff --git a/test/src/browser/cdp/selectivity/index.ts b/test/src/browser/cdp/selectivity/index.ts index d9de81897..8285fe8b8 100644 --- a/test/src/browser/cdp/selectivity/index.ts +++ b/test/src/browser/cdp/selectivity/index.ts @@ -2,6 +2,7 @@ import sinon, { SinonStub } from "sinon"; import proxyquire from "proxyquire"; import type { ExistingBrowser } from "src/browser/existing-browser"; import type { Test } from "src/types"; +import { SelectivityMode, type SelectivityModeValue } from "src/config/types"; describe("CDP/Selectivity", () => { const sandbox = sinon.createSandbox(); @@ -27,7 +28,7 @@ describe("CDP/Selectivity", () => { let browserMock: { config: { selectivity: { - enabled: boolean; + enabled: SelectivityModeValue; sourceRoot: string; testDependenciesPath: string; compression: "none"; @@ -82,7 +83,7 @@ describe("CDP/Selectivity", () => { browserMock = { config: { selectivity: { - enabled: true, + enabled: SelectivityMode.Enabled, sourceRoot: "/test/source-root", testDependenciesPath: "/test/dependencies", compression: "none", @@ -125,17 +126,19 @@ describe("CDP/Selectivity", () => { }); describe("startSelectivity", () => { - it("should return no-op function if selectivity is disabled", async () => { - browserMock.config.selectivity.enabled = false; + [SelectivityMode.Disabled, SelectivityMode.ReadOnly].forEach(mode => { + it(`should return no-op function if selectivity mode is ${mode}`, async () => { + browserMock.config.selectivity.enabled = mode; - const stopFn = await startSelectivity(browserMock as unknown as ExistingBrowser); + const stopFn = await startSelectivity(browserMock as unknown as ExistingBrowser); - assert.isFunction(stopFn); + assert.isFunction(stopFn); - await stopFn({ id: "test", browserId: "chrome" } as Test, true); + await stopFn({ id: "test", browserId: "chrome" } as Test, true); - assert.notCalled(CSSSelectivityStub); - assert.notCalled(JSSelectivityStub); + assert.notCalled(CSSSelectivityStub); + assert.notCalled(JSSelectivityStub); + }); }); it("should return no-op function if browser is not Chromium", async () => { @@ -299,44 +302,46 @@ describe("CDP/Selectivity", () => { }; }); - it("should skip browsers with selectivity disabled", async () => { - configMock.getBrowserIds.returns(["chrome", "firefox"]); - configMock.forBrowser - .withArgs("chrome") - .returns({ - selectivity: { - enabled: false, - testDependenciesPath: "/test/path", - compression: "none", - disableSelectivityPatterns: ["src/**/*.js"], - }, - }) - .withArgs("firefox") - .returns({ - selectivity: { - enabled: true, - testDependenciesPath: "/test/path", - compression: "none", - disableSelectivityPatterns: ["src/**/*.js"], - }, - }); - - hashReaderMock.patternHasChanged.resolves(true); - - await updateSelectivityHashes(configMock as any); - - assert.calledOnce(getHashReaderStub); // Only for firefox - assert.calledWith(getHashReaderStub, "/test/path", "none"); - assert.calledOnce(hashWriterMock.addPatternDependencyHash); - assert.calledWith(hashWriterMock.addPatternDependencyHash, "src/**/*.js"); - assert.calledOnce(hashWriterMock.commit); + [SelectivityMode.Disabled, SelectivityMode.ReadOnly].forEach(mode => { + it(`should skip browsers with selectivity mode ${mode}`, async () => { + configMock.getBrowserIds.returns(["chrome", "firefox"]); + configMock.forBrowser + .withArgs("chrome") + .returns({ + selectivity: { + enabled: mode, + testDependenciesPath: "/test/path", + compression: "none", + disableSelectivityPatterns: ["src/**/*.js"], + }, + }) + .withArgs("firefox") + .returns({ + selectivity: { + enabled: SelectivityMode.Enabled, + testDependenciesPath: "/test/path", + compression: "none", + disableSelectivityPatterns: ["src/**/*.js"], + }, + }); + + hashReaderMock.patternHasChanged.resolves(true); + + await updateSelectivityHashes(configMock as any); + + assert.calledOnce(getHashReaderStub); // Only for firefox + assert.calledWith(getHashReaderStub, "/test/path", "none"); + assert.calledOnce(hashWriterMock.addPatternDependencyHash); + assert.calledWith(hashWriterMock.addPatternDependencyHash, "src/**/*.js"); + assert.calledOnce(hashWriterMock.commit); + }); }); it("should update hashes for changed patterns", async () => { configMock.getBrowserIds.returns(["chrome"]); configMock.forBrowser.withArgs("chrome").returns({ selectivity: { - enabled: true, + enabled: SelectivityMode.Enabled, testDependenciesPath: "/test/path", compression: "gz", disableSelectivityPatterns: ["pattern1", "pattern2", "pattern3"], @@ -365,7 +370,7 @@ describe("CDP/Selectivity", () => { configMock.getBrowserIds.returns(["chrome"]); configMock.forBrowser.withArgs("chrome").returns({ selectivity: { - enabled: true, + enabled: SelectivityMode.Enabled, testDependenciesPath: "/test/path", compression: "none", disableSelectivityPatterns: ["pattern1", "pattern2"], @@ -386,7 +391,7 @@ describe("CDP/Selectivity", () => { .withArgs("chrome") .returns({ selectivity: { - enabled: true, + enabled: SelectivityMode.Enabled, testDependenciesPath: "/test/chrome", compression: "none", disableSelectivityPatterns: ["chrome-pattern"], @@ -395,7 +400,7 @@ describe("CDP/Selectivity", () => { .withArgs("firefox") .returns({ selectivity: { - enabled: true, + enabled: SelectivityMode.Enabled, testDependenciesPath: "/test/firefox", compression: "gz", disableSelectivityPatterns: ["firefox-pattern"], @@ -413,25 +418,24 @@ describe("CDP/Selectivity", () => { assert.calledTwice(hashWriterMock.commit); }); - it("should throw error with cause when commit fails", async () => { + it("should update hashes for WriteOnly mode", async () => { configMock.getBrowserIds.returns(["chrome"]); configMock.forBrowser.withArgs("chrome").returns({ selectivity: { - enabled: true, + enabled: SelectivityMode.WriteOnly, testDependenciesPath: "/test/path", compression: "none", - disableSelectivityPatterns: ["pattern1"], + disableSelectivityPatterns: ["src/**/*.js"], }, }); hashReaderMock.patternHasChanged.resolves(true); - const commitError = new Error("Failed to write file"); - hashWriterMock.commit.rejects(commitError); - await assert.isRejected( - updateSelectivityHashes(configMock as any), - /Selectivity: couldn't save test dependencies hash/, - ); + await updateSelectivityHashes(configMock as any); + + assert.calledOnce(hashWriterMock.addPatternDependencyHash); + assert.calledWith(hashWriterMock.addPatternDependencyHash, "src/**/*.js"); + assert.calledOnce(hashWriterMock.commit); }); }); }); diff --git a/test/src/browser/cdp/selectivity/modes.ts b/test/src/browser/cdp/selectivity/modes.ts new file mode 100644 index 000000000..48264fd3f --- /dev/null +++ b/test/src/browser/cdp/selectivity/modes.ts @@ -0,0 +1,47 @@ +import { SelectivityMode } from "src/config/types"; +import { + selectivityIsDisabled, + selectivityShouldWrite, + selectivityShouldRead, +} from "src/browser/cdp/selectivity/modes"; + +describe("CDP/Selectivity/Modes", () => { + describe("selectivityIsDisabled", () => { + [ + { mode: SelectivityMode.Disabled, expected: true }, + { mode: SelectivityMode.Enabled, expected: false }, + { mode: SelectivityMode.ReadOnly, expected: false }, + { mode: SelectivityMode.WriteOnly, expected: false }, + ].forEach(({ mode, expected }) => { + it(`should return ${expected} when mode is ${mode}`, () => { + assert.equal(selectivityIsDisabled(mode), expected); + }); + }); + }); + + describe("selectivityShouldWrite", () => { + [ + { mode: SelectivityMode.Enabled, expected: true }, + { mode: SelectivityMode.WriteOnly, expected: true }, + { mode: SelectivityMode.Disabled, expected: false }, + { mode: SelectivityMode.ReadOnly, expected: false }, + ].forEach(({ mode, expected }) => { + it(`should return ${expected} when mode is ${mode}`, () => { + assert.equal(selectivityShouldWrite(mode), expected); + }); + }); + }); + + describe("selectivityShouldRead", () => { + [ + { mode: SelectivityMode.Enabled, expected: true }, + { mode: SelectivityMode.ReadOnly, expected: true }, + { mode: SelectivityMode.Disabled, expected: false }, + { mode: SelectivityMode.WriteOnly, expected: false }, + ].forEach(({ mode, expected }) => { + it(`should return ${expected} when mode is ${mode}`, () => { + assert.equal(selectivityShouldRead(mode), expected); + }); + }); + }); +}); diff --git a/test/src/browser/cdp/selectivity/runner.ts b/test/src/browser/cdp/selectivity/runner.ts index 163b9a384..f5d26c316 100644 --- a/test/src/browser/cdp/selectivity/runner.ts +++ b/test/src/browser/cdp/selectivity/runner.ts @@ -3,6 +3,7 @@ import proxyquire from "proxyquire"; import type { SelectivityRunner } from "src/browser/cdp/selectivity/runner"; import type { Test } from "src/types"; import { MasterEvents } from "src/events"; +import { SelectivityMode, type SelectivityModeValue } from "src/config/types"; describe("SelectivityRunner", () => { const sandbox = sinon.createSandbox(); @@ -13,9 +14,9 @@ describe("SelectivityRunner", () => { let getTestDependenciesReaderStub: SinonStub; let mainRunnerMock: { on: SinonStub }; - let configMock: { forBrowser: SinonStub }; + let configMock: { forBrowser: SinonStub; getBrowserIds: SinonStub }; let runTestFnMock: SinonStub; - let hashReaderMock: { patternHasChanged: SinonStub; getTestChangedDeps: SinonStub }; + let hashReaderMock: { patternHasChanged: SinonStub; getTestChangedDeps: SinonStub; clearCache: SinonStub }; let hashWriterMock: { addTestDependencyHashes: SinonStub }; let testDepsReaderMock: { getFor: SinonStub }; @@ -28,6 +29,7 @@ describe("SelectivityRunner", () => { hashReaderMock = { patternHasChanged: sandbox.stub(), getTestChangedDeps: sandbox.stub(), + clearCache: sandbox.stub(), }; hashWriterMock = { addTestDependencyHashes: sandbox.stub(), @@ -41,6 +43,7 @@ describe("SelectivityRunner", () => { }; configMock = { forBrowser: sandbox.stub(), + getBrowserIds: sandbox.stub().returns([]), }; runTestFnMock = sandbox.stub(); @@ -85,7 +88,7 @@ describe("SelectivityRunner", () => { let runner: SelectivityRunner; let browserConfigMock: { selectivity: { - enabled: boolean; + enabled: SelectivityModeValue; testDependenciesPath: string; compression: string; disableSelectivityPatterns: string[]; @@ -96,7 +99,7 @@ describe("SelectivityRunner", () => { beforeEach(() => { browserConfigMock = { selectivity: { - enabled: true, + enabled: SelectivityMode.Enabled, testDependenciesPath: "/test/path", compression: "none", disableSelectivityPatterns: [], @@ -108,18 +111,21 @@ describe("SelectivityRunner", () => { fullTitle: () => "Test Suite Test Case", } as Test; + configMock.getBrowserIds.returns(["chrome"]); configMock.forBrowser.returns(browserConfigMock); runner = new SelectivityRunnerClass(mainRunnerMock as any, configMock as any, runTestFnMock); }); - it("should run test if selectivity is disabled for browser", async () => { - browserConfigMock.selectivity.enabled = false; + [SelectivityMode.Disabled, SelectivityMode.WriteOnly].forEach(mode => { + it(`should run test if selectivity mode is ${mode}`, async () => { + browserConfigMock.selectivity.enabled = mode; - runner.startTestCheckToRun(testMock, "chrome"); - await runner.runNecessaryTests(); + runner.startTestCheckToRun(testMock, "chrome"); + await runner.runNecessaryTests(); - assert.calledOnce(runTestFnMock); - assert.calledWith(runTestFnMock, testMock, "chrome"); + assert.calledOnce(runTestFnMock); + assert.calledWith(runTestFnMock, testMock, "chrome"); + }); }); it("should run test if shouldDisableSelectivity option is true", async () => { @@ -157,6 +163,7 @@ describe("SelectivityRunner", () => { browserConfigMock.selectivity.enabled = true; browserConfigMock.selectivity.disableSelectivityPatterns = ["src/**/*.js"]; hashReaderMock.patternHasChanged.resolves(false); + configMock.getBrowserIds.returns(["chrome"]); const testDeps = { css: [], js: ["src/app.js"], modules: [] }; testDepsReaderMock.getFor.resolves(testDeps); @@ -173,7 +180,6 @@ describe("SelectivityRunner", () => { assert.calledOnce(runTestFnMock); assert.calledWith(runTestFnMock, disabledTestMock, "chrome"); assert.notCalled(getTestDependenciesReaderStub); - assert.notCalled(getHashReaderStub); }); it("should run test if browser selectivity is disabled due to no patterns", async () => { @@ -318,7 +324,7 @@ describe("SelectivityRunner", () => { it("should handle different browsers separately", async () => { const chromeConfig = { selectivity: { - enabled: true, + enabled: SelectivityMode.Enabled, testDependenciesPath: "/test/chrome", compression: "none", disableSelectivityPatterns: ["src/**/*.js"], @@ -326,7 +332,7 @@ describe("SelectivityRunner", () => { }; const firefoxConfig = { selectivity: { - enabled: true, + enabled: SelectivityMode.Enabled, testDependenciesPath: "/test/firefox", compression: "gz", disableSelectivityPatterns: ["test/**/*.js"], @@ -366,7 +372,7 @@ describe("SelectivityRunner", () => { it("should wait for all processing tests to complete", async () => { const browserConfigMock = { selectivity: { - enabled: true, + enabled: SelectivityMode.Enabled, testDependenciesPath: "/test/path", compression: "none", disableSelectivityPatterns: [], @@ -378,6 +384,7 @@ describe("SelectivityRunner", () => { fullTitle: () => "Test Suite Test Case", } as Test; + configMock.getBrowserIds.returns(["chrome"]); configMock.forBrowser.returns(browserConfigMock); const testDeps = { css: [], js: ["src/app.js"], modules: [] }; diff --git a/test/src/worker/runner/index.js b/test/src/worker/runner/index.js index e49fdf31a..3d3efd1aa 100644 --- a/test/src/worker/runner/index.js +++ b/test/src/worker/runner/index.js @@ -248,5 +248,53 @@ describe("worker/runner", () => { browserId: "bro", }); }); + + it("should run with dependency collecting if selectivity mode is write-only", async () => { + const runner = mkRunner_({ + config: makeConfigStub({ + system: { testRunEnv: NODEJS_TEST_RUN_ENV }, + selectivity: { enabled: "write-only" }, + }), + }); + await runner.runTest(null, { file: "some/file.js", browserId: "bro" }); + + assert.calledOnce(runWithTestplaneDependenciesCollecting); + assert.calledOnceWith(CachingTestParser.prototype.parse, { + file: "some/file.js", + browserId: "bro", + }); + }); + + it("should not run with dependency collecting if selectivity is disabled", async () => { + const runner = mkRunner_({ + config: makeConfigStub({ + system: { testRunEnv: NODEJS_TEST_RUN_ENV }, + selectivity: { enabled: false }, + }), + }); + await runner.runTest(null, { file: "some/file.js", browserId: "bro" }); + + assert.notCalled(runWithTestplaneDependenciesCollecting); + assert.calledOnceWith(CachingTestParser.prototype.parse, { + file: "some/file.js", + browserId: "bro", + }); + }); + + it("should not run with dependency collecting if selectivity mode is read-only", async () => { + const runner = mkRunner_({ + config: makeConfigStub({ + system: { testRunEnv: NODEJS_TEST_RUN_ENV }, + selectivity: { enabled: "read-only" }, + }), + }); + await runner.runTest(null, { file: "some/file.js", browserId: "bro" }); + + assert.notCalled(runWithTestplaneDependenciesCollecting); + assert.calledOnceWith(CachingTestParser.prototype.parse, { + file: "some/file.js", + browserId: "bro", + }); + }); }); });