fix(misc): move generator should null-check cypress props (#15436)

This commit is contained in:
William Neely 2023-03-14 11:43:25 -04:00 committed by GitHub
parent 481899ce9f
commit 46bc6af3c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 8 deletions

View File

@ -59,6 +59,25 @@ describe('updateCypressConfig', () => {
});
});
it('should noop if the videos and screenshots folders are not defined', async () => {
const cypressJson = {
fileServerFolder: '.',
fixturesFolder: './src/fixtures',
integrationFolder: './src/integration',
pluginsFile: './src/plugins/index',
supportFile: false,
video: false,
chromeWebSecurity: false,
};
writeJson(tree, '/libs/my-destination/cypress.json', cypressJson);
updateCypressConfig(tree, schema, projectConfig);
expect(readJson(tree, '/libs/my-destination/cypress.json')).toEqual(
cypressJson
);
});
it('should handle updating cypress.config.ts', async () => {
tree.write(
'/libs/my-destination/cypress.config.ts',

View File

@ -28,14 +28,20 @@ export function updateCypressConfig(
const cypressJson = JSON.parse(
tree.read(cypressJsonPath).toString('utf-8')
) as PartialCypressJson;
cypressJson.videosFolder = cypressJson.videosFolder.replace(
project.root,
schema.relativeToRootDestination
);
cypressJson.screenshotsFolder = cypressJson.screenshotsFolder.replace(
project.root,
schema.relativeToRootDestination
);
// videosFolder is not required because videos can be turned off - it also has a default
if (cypressJson.videosFolder) {
cypressJson.videosFolder = cypressJson.videosFolder.replace(
project.root,
schema.relativeToRootDestination
);
}
// screenshotsFolder is not required as it has a default
if (cypressJson.screenshotsFolder) {
cypressJson.screenshotsFolder = cypressJson.screenshotsFolder.replace(
project.root,
schema.relativeToRootDestination
);
}
tree.write(cypressJsonPath, JSON.stringify(cypressJson));
return tree;