-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from joomcode/fix/update-config-after-do-befor…
…e-functions fix: update pack config by values from `doBeforePack` functions
- Loading branch information
Showing
7 changed files
with
88 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {readFileSync} from 'node:fs'; | ||
|
||
import {READ_FILE_OPTIONS, START_INFO_PATH} from '../../constants/internal'; | ||
|
||
import type {StartInfo} from '../../types/internal'; | ||
|
||
/** | ||
* Read start info from tmp directory in sync manner. | ||
* @internal | ||
*/ | ||
export const readStartInfoSync = (): StartInfo => { | ||
const startInfoJsonString = readFileSync(START_INFO_PATH, READ_FILE_OPTIONS); | ||
|
||
return JSON.parse(startInfoJsonString) as StartInfo; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// eslint-disable-next-line import/no-internal-modules | ||
import {readStartInfoSync} from '../fs/readStartInfoSync'; | ||
|
||
import {updateConfig} from './updateConfig'; | ||
|
||
import type {FullPackConfig} from '../../types/internal'; | ||
|
||
let updatedConfig: FullPackConfig | undefined; | ||
|
||
/** | ||
* Get full pack configuration object. | ||
* This function can only be called after the `E2edRunEvent` is registered, | ||
* because the packs with configurations (`e2ed/packs`) is compiled when this event is registered. | ||
*/ | ||
export const getFullPackConfig = < | ||
CustomPackProperties = unknown, | ||
CustomReportProperties = unknown, | ||
SkipTests = unknown, | ||
TestMeta = unknown, | ||
>(): FullPackConfig<CustomPackProperties, CustomReportProperties, SkipTests, TestMeta> => { | ||
if (updatedConfig === undefined) { | ||
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires | ||
const {fullPackConfig} = require<typeof import('../../testcaferc')>('../../testcaferc'); | ||
|
||
updatedConfig = fullPackConfig; | ||
|
||
try { | ||
const startInfo = readStartInfoSync(); | ||
|
||
updateConfig(updatedConfig, startInfo); | ||
} catch (error) {} | ||
} | ||
|
||
return updatedConfig as unknown as FullPackConfig< | ||
CustomPackProperties, | ||
CustomReportProperties, | ||
SkipTests, | ||
TestMeta | ||
>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export {getFullPackConfig} from './getFullPackConfig'; | ||
/** @internal */ | ||
export {updateConfig} from './updateConfig'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type {FullPackConfig, StartInfo} from '../../types/internal'; | ||
|
||
/** | ||
* Updates full pack config by values from `startInfo` (getted by `doBeforePack` functions). | ||
* @internal | ||
*/ | ||
export const updateConfig = (fullPackConfig: FullPackConfig, startInfo: StartInfo): void => { | ||
for (const field of Object.keys(fullPackConfig) as (keyof FullPackConfig)[]) { | ||
if (field === 'doAfterPack' || field === 'doBeforePack') { | ||
continue; | ||
} | ||
|
||
if (typeof fullPackConfig[field] === 'function') { | ||
continue; | ||
} | ||
|
||
// @ts-expect-error: full pack config have different types of field values | ||
fullPackConfig[field] = startInfo.fullPackConfig[field]; // eslint-disable-line no-param-reassign | ||
} | ||
}; |