Skip to content

Commit 223143f

Browse files
authored
test(testing): Add new addResolution test helper (#7460)
1 parent 80e19f2 commit 223143f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

integration/models/applicationConfig.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const applicationConfig = () => {
2121
const envFormatters = { public: (key: string) => key, private: (key: string) => key };
2222
const logger = createLogger({ prefix: 'appConfig', color: 'yellow' });
2323
const dependencies = new Map<string, string>();
24+
const resolutions = new Map<string, string>();
2425

2526
const self = {
2627
clone: () => {
@@ -32,6 +33,7 @@ export const applicationConfig = () => {
3233
clone.useTemplate(template);
3334
}
3435
dependencies.forEach((v, k) => clone.addDependency(k, v));
36+
resolutions.forEach((v, k) => clone.addResolution(k, v));
3537
Object.entries(scripts).forEach(([k, v]) => clone.addScript(k as keyof typeof scripts, v));
3638
files.forEach((v, k) => clone.addFile(k, () => v));
3739
return clone;
@@ -76,6 +78,10 @@ export const applicationConfig = () => {
7678
}
7779
return self;
7880
},
81+
addResolution: (name: string, version: string) => {
82+
resolutions.set(name, version);
83+
return self;
84+
},
7985
/**
8086
* Creates a new application directory and copies the template files (and any overrides) to it.
8187
* The application directory is created in the `constants.TMP_DIR` directory.
@@ -125,6 +131,15 @@ export const applicationConfig = () => {
125131
await fs.writeJSON(packageJsonPath, contents, { spaces: 2 });
126132
}
127133

134+
// Adjust package.json resolutions
135+
if (resolutions.size > 0) {
136+
const packageJsonPath = path.resolve(appDirPath, 'package.json');
137+
logger.info(`Modifying resolutions in "${packageJsonPath}"`);
138+
const contents = await fs.readJSON(packageJsonPath);
139+
contents.resolutions = { ...contents.resolutions, ...Object.fromEntries(resolutions) };
140+
await fs.writeJSON(packageJsonPath, contents, { spaces: 2 });
141+
}
142+
128143
return application(self, appDirPath, appDirName, serverUrl);
129144
},
130145
setEnvWriter: () => {

0 commit comments

Comments
 (0)