2020-03-04 07:12:52 +08:00
|
|
|
'use strict';
|
|
|
|
const {
|
|
|
|
promises: { readFile },
|
|
|
|
} = require('fs');
|
|
|
|
const { resolve } = require('path');
|
|
|
|
|
2020-06-01 20:48:23 +08:00
|
|
|
// @todo use https://github.com/bahmutov/cypress-extends when possible
|
2021-01-20 14:59:48 +08:00
|
|
|
module.exports = async (baseConfig) => {
|
2020-03-04 07:12:52 +08:00
|
|
|
// From CLI
|
|
|
|
const {
|
2020-06-01 20:48:23 +08:00
|
|
|
env: { CWD, UPDATE_SCREENSHOTS },
|
2020-03-04 07:12:52 +08:00
|
|
|
} = baseConfig;
|
|
|
|
|
|
|
|
if (CWD) {
|
2020-05-26 07:28:35 +08:00
|
|
|
// @todo: https://github.com/cypress-io/cypress/issues/6406
|
|
|
|
const jsonReporter = require.resolve('@mochajs/json-file-reporter');
|
|
|
|
|
2020-06-12 04:31:49 +08:00
|
|
|
// @todo `baseUrl: env.CYPRESS_BASEURL`
|
2020-03-04 07:12:52 +08:00
|
|
|
const projectConfig = {
|
2020-03-27 00:15:58 +08:00
|
|
|
fixturesFolder: `${CWD}/cypress/fixtures`,
|
2020-03-04 07:12:52 +08:00
|
|
|
integrationFolder: `${CWD}/cypress/integration`,
|
2020-05-26 07:28:35 +08:00
|
|
|
reporter: jsonReporter,
|
2020-05-26 03:07:28 +08:00
|
|
|
reporterOptions: {
|
|
|
|
output: `${CWD}/cypress/report.json`,
|
|
|
|
},
|
2020-06-01 20:48:23 +08:00
|
|
|
screenshotsFolder: `${CWD}/cypress/screenshots/${UPDATE_SCREENSHOTS ? 'expected' : 'actual'}`,
|
2020-03-04 07:12:52 +08:00
|
|
|
videosFolder: `${CWD}/cypress/videos`,
|
|
|
|
};
|
|
|
|
|
|
|
|
const customProjectConfig = await readFile(`${CWD}/cypress.json`, 'utf8')
|
|
|
|
.then(JSON.parse)
|
2021-01-20 14:59:48 +08:00
|
|
|
.then((config) => {
|
2020-03-04 07:12:52 +08:00
|
|
|
const pathKeys = [
|
|
|
|
'fileServerFolder',
|
|
|
|
'fixturesFolder',
|
|
|
|
'ignoreTestFiles',
|
|
|
|
'integrationFolder',
|
|
|
|
'pluginsFile',
|
|
|
|
'screenshotsFolder',
|
|
|
|
'supportFile',
|
|
|
|
'testFiles',
|
|
|
|
'videosFolder',
|
|
|
|
];
|
|
|
|
|
|
|
|
return Object.fromEntries(
|
|
|
|
Object.entries(config).map(([key, value]) => {
|
|
|
|
if (pathKeys.includes(key)) {
|
|
|
|
return [key, resolve(CWD, value)];
|
|
|
|
} else {
|
|
|
|
return [key, value];
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
2021-01-20 14:59:48 +08:00
|
|
|
.catch((error) => {
|
2020-03-04 07:12:52 +08:00
|
|
|
if (error.code === 'ENOENT') {
|
|
|
|
// File is optional
|
2020-05-26 03:07:28 +08:00
|
|
|
return {};
|
2020-03-04 07:12:52 +08:00
|
|
|
} else {
|
|
|
|
// Unexpected error
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-26 03:07:28 +08:00
|
|
|
return {
|
|
|
|
...baseConfig,
|
|
|
|
...projectConfig,
|
|
|
|
...customProjectConfig,
|
|
|
|
reporterOptions: {
|
|
|
|
...baseConfig.reporterOptions,
|
|
|
|
...projectConfig.reporterOptions,
|
|
|
|
...customProjectConfig.reporterOptions,
|
|
|
|
},
|
|
|
|
};
|
2020-03-04 07:12:52 +08:00
|
|
|
} else {
|
|
|
|
// Temporary legacy support for Grafana core (using `yarn start`)
|
|
|
|
return baseConfig;
|
|
|
|
}
|
|
|
|
};
|