Skip to content

Commit 764f470

Browse files
committed
Test inputs.configFile mutation in tests
1 parent d149f93 commit 764f470

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

src/config-utils.test.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,22 +2317,25 @@ test("determineUserConfig - loads config file", async (t) => {
23172317
const logger = new RecordingLogger();
23182318
const env = util.getEnv(DEFAULT_ACTIONS_VARS);
23192319

2320+
const inputs = createTestInitConfigInputs({
2321+
configInput: undefined,
2322+
configFile: configFilePath,
2323+
});
23202324
const result = await configUtils.determineUserConfig(
23212325
logger,
23222326
env,
23232327
createFeatures([]),
23242328
tmpDir,
2325-
createTestInitConfigInputs({
2326-
configInput: undefined,
2327-
configFile: configFilePath,
2328-
}),
2329+
inputs,
23292330
);
23302331

23312332
// The loaded configuration should match `simpleConfigFileContents`.
23322333
t.deepEqual(result, {
23332334
name: "my config",
23342335
queries: [{ uses: "./foo_file" }],
23352336
});
2337+
// The `configFile` input should not have changed.
2338+
t.is(inputs.configFile, configFilePath);
23362339
// And the path of the input config file should have been logged, while the
23372340
// other two origin messages should not have been logged.
23382341
t.true(logger.hasMessage(`Using configuration file: ${configFilePath}`));
@@ -2351,30 +2354,32 @@ test("determineUserConfig - loads config input", async (t) => {
23512354
await withTmpDir(async (tmpDir) => {
23522355
const logger = new RecordingLogger();
23532356
const env = util.getEnv(DEFAULT_ACTIONS_VARS);
2357+
const expectedConfigPath = configUtils.userConfigFromActionPath(tmpDir);
23542358

2359+
const inputs = createTestInitConfigInputs({
2360+
configInput: simpleConfigFileContents,
2361+
configFile: undefined,
2362+
});
23552363
const result = await configUtils.determineUserConfig(
23562364
logger,
23572365
env,
23582366
createFeatures([]),
23592367
tmpDir,
2360-
createTestInitConfigInputs({
2361-
configInput: simpleConfigFileContents,
2362-
configFile: undefined,
2363-
}),
2368+
inputs,
23642369
);
23652370

23662371
// The loaded configuration should match `simpleConfigFileContents`.
23672372
t.deepEqual(result, {
23682373
name: "my config",
23692374
queries: [{ uses: "./foo_file" }],
23702375
});
2376+
// The `configFile` input should have been mutated to the generated path.
2377+
t.is(inputs.configFile, expectedConfigPath);
23712378
// And the input source and path of the generated config file should have been logged,
23722379
// while the message about no configuration input should not have been logged.
23732380
t.true(logger.hasMessage("Using config from action input:"));
23742381
t.true(
2375-
logger.hasMessage(
2376-
`Using configuration file: ${configUtils.userConfigFromActionPath(tmpDir)}`,
2377-
),
2382+
logger.hasMessage(`Using configuration file: ${expectedConfigPath}`),
23782383
);
23792384
t.false(logger.hasMessage("No configuration file was provided"));
23802385
// But the warning about both inputs should not have been logged.
@@ -2393,22 +2398,25 @@ test("determineUserConfig - ignores config file input when both specified", asyn
23932398
const configFilePath = createConfigFile(otherConfigFileContents, tmpDir);
23942399
const expectedConfigPath = configUtils.userConfigFromActionPath(tmpDir);
23952400

2401+
const inputs = createTestInitConfigInputs({
2402+
configInput: simpleConfigFileContents,
2403+
configFile: configFilePath,
2404+
});
23962405
const result = await configUtils.determineUserConfig(
23972406
logger,
23982407
env,
23992408
createFeatures([]),
24002409
tmpDir,
2401-
createTestInitConfigInputs({
2402-
configInput: simpleConfigFileContents,
2403-
configFile: configFilePath,
2404-
}),
2410+
inputs,
24052411
);
24062412

24072413
// The loaded configuration should match `simpleConfigFileContents`.
24082414
t.deepEqual(result, {
24092415
name: "my config",
24102416
queries: [{ uses: "./foo_file" }],
24112417
});
2418+
// The `configFile` input should have been mutated to the generated path.
2419+
t.is(inputs.configFile, expectedConfigPath);
24122420
// And the path of the generated config file should have been logged.
24132421
t.true(
24142422
logger.hasMessage(

0 commit comments

Comments
 (0)