mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Check two locations for config.json, as it's in a different location in CI
This commit is contained in:
@@ -1,15 +1,34 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
// Plugins enable you to tap into, modify, or extend the internal behavior of Cypress
|
// Plugins enable you to tap into, modify, or extend the internal behavior of Cypress
|
||||||
// For more info, visit https://on.cypress.io/plugins-api
|
// For more info, visit https://on.cypress.io/plugins-api
|
||||||
module.exports = (on, config) => {
|
module.exports = (on, config) => {
|
||||||
// Define "log" and "table" tasks, used for logging accessibility errors during CI
|
|
||||||
// Borrowed from https://github.com/component-driven/cypress-axe#in-cypress-plugins-file
|
|
||||||
on('task', {
|
on('task', {
|
||||||
|
// Define "log" and "table" tasks, used for logging accessibility errors during CI
|
||||||
|
// Borrowed from https://github.com/component-driven/cypress-axe#in-cypress-plugins-file
|
||||||
log(message: string) {
|
log(message: string) {
|
||||||
console.log(message);
|
console.log(message);
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
table(message: string) {
|
table(message: string) {
|
||||||
console.table(message);
|
console.table(message);
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
// Cypress doesn't have access to the running application in Node.js.
|
||||||
|
// So, it's not possible to inject or load the AppConfig or environment of the Angular UI.
|
||||||
|
// Instead, we'll read our running application's config.json, which contains the configs &
|
||||||
|
// is regenerated at runtime each time the Angular UI application starts up.
|
||||||
|
readUIConfig() {
|
||||||
|
// Check if we have a config.json in the src/assets. If so, use that.
|
||||||
|
// This is where it's written when running "ng e2e" or "yarn serve"
|
||||||
|
if (fs.existsSync('./src/assets/config.json')) {
|
||||||
|
return fs.readFileSync('./src/assets/config.json', 'utf8');
|
||||||
|
// Otherwise, check the dist/browser/assets
|
||||||
|
// This is where it's written when running "serve:ssr", which is what CI uses to start the frontend
|
||||||
|
} else if (fs.existsSync('./dist/browser/assets/config.json')) {
|
||||||
|
return fs.readFileSync('./dist/browser/assets/config.json', 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -34,9 +34,9 @@ function login(email: string, password: string): void {
|
|||||||
// So, it's not possible to inject or load the AppConfig or environment of the Angular UI.
|
// So, it's not possible to inject or load the AppConfig or environment of the Angular UI.
|
||||||
// Instead, we'll read our running application's config.json, which contains the configs &
|
// Instead, we'll read our running application's config.json, which contains the configs &
|
||||||
// is regenerated at runtime each time the Angular UI application starts up.
|
// is regenerated at runtime each time the Angular UI application starts up.
|
||||||
cy.readFile('./src/assets/config.json').then((str) => {
|
cy.task('readUIConfig').then((str: string) => {
|
||||||
// Parse JSON file into a JSON object
|
// Parse config into a JSON object
|
||||||
const config = JSON.parse(JSON.stringify(str));
|
const config = JSON.parse(str);
|
||||||
|
|
||||||
// Find the URL of our REST API. Have a fallback ready, just in case 'rest.baseUrl' cannot be found.
|
// Find the URL of our REST API. Have a fallback ready, just in case 'rest.baseUrl' cannot be found.
|
||||||
let baseRestUrl = FALLBACK_TEST_REST_BASE_URL;
|
let baseRestUrl = FALLBACK_TEST_REST_BASE_URL;
|
||||||
|
Reference in New Issue
Block a user