Skip to content

Commit

Permalink
Attempt at making tests work on github actions
Browse files Browse the repository at this point in the history
Also: more concise deubg messages for tests
  • Loading branch information
Mocca101 committed Aug 28, 2023
1 parent 9433cd8 commit 1994b0c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 37 deletions.
11 changes: 10 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000'
baseUrl: 'http://localhost:3000',
setupNodeEvents (on, _config) {
on('task', {
log (message) {
console.log(message);

return null;
}
});
}
}
});
30 changes: 21 additions & 9 deletions cypress/e2e/MainToOtherPages.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
// Import discovery config
import discoveryConfig from '../../config/discoveryConfig.json';

describe('Navigation', () => {
it('From Main to Map', () => {
beforeEach(() => {
cy.visit('/');
});

it('Main to Map', () => {
if (discoveryConfig.APIbase === undefined) {
cy.task('log', 'APIbase is undefined, skipping test');
this.skip();
}

cy.get('[data-test="main-map-btn"]')
.should('exist')
Expand All @@ -11,14 +20,17 @@ describe('Navigation', () => {
.should('exist');
});

it('From Main to Data', () => {
cy.visit('/');
it('Main to Data', () => {
if (discoveryConfig.APIbase === undefined) {
cy.get('[data-test="main-data-btn"]')
.should('not.exist');
} else {
cy.get('[data-test="main-data-btn"]')
.should('exist')
.click();

cy.get('[data-test="main-data-btn"]')
.should('exist')
.click();

cy.get('[data-test="data-page-container"]')
.should('exist');
cy.get('[data-test="data-page-container"]')
.should('exist');
}
});
});
51 changes: 25 additions & 26 deletions deployment/loadContent.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import child_process from 'child_process';
import fs from 'fs-extra'
import fs from 'fs-extra';

const clonedContentPath = 'temp';

const repo = process.env["CONTENT_REPO"] ?? 'Mocca101/oad-content-test';
const branch = process.env["CONTENT_BRANCH"] ?? 'main';
const repo = process.env.CONTENT_REPO ?? 'acdh-oeaw/OpenAtlas-Discovery-Content-Template';
const branch = process.env.CONTENT_BRANCH ?? 'main';
const configSourcePath = `${clonedContentPath}/discoveryConfig.json`;
const configDestPath = `config/discoveryConfig.json`;
const configDestPath = 'config/discoveryConfig.json';

const contentSourcePath = `${clonedContentPath}/content`;
const contentDestPath = `content`;
const contentDestPath = 'content';

const publicSourcePath = `${clonedContentPath}/public`;
const publicDestPath = `public`;
const publicDestPath = 'public';

cloneRepo(clonedContentPath, repo, branch);
// Log the commit hash of the content repo
console.log('Content repo commit hash: ', child_process.execSync(`git -C ${clonedContentPath} rev-parse HEAD`).toString().trim());

if(fs.existsSync(clonedContentPath)) {
if (fs.existsSync(clonedContentPath)) {
handleConfig();
handleContent();
handlePublic();
Expand All @@ -32,21 +32,20 @@ if(fs.existsSync(clonedContentPath)) {
* @param {string} repo following then format "user/repositoryName"
* @param {string} branch
*/
function cloneRepo(targetpath, repo, branch, useHttp = true) {
function cloneRepo (targetpath, repo, branch, useHttp = true) {
// From https://cheatcode.co/tutorials/how-to-clone-and-sync-a-github-repo-via-node-js
// child_process.execSync(`git clone ${getBranch(branch)} https://${username}:${process.env.PERSONAL_ACCESS_TOKEN}@github.com/${username}/${repo}.git ${targetpath}`);

if(fs.existsSync(targetpath)) {
if (fs.existsSync(targetpath)) {
fs.rmSync(clonedContentPath, { recursive: true, force: true });
}

if(useHttp) {
if (useHttp) {
console.log(`Attempting to clone ${getBranch(branch)} on https://github.com/${repo}.git to ${targetpath}`);
child_process.execSync(`git clone ${getBranch(branch)} https://github.com/${repo}.git ${targetpath}`);
} else {
console.log(`Attempting to clone ${getBranch(branch)} on [email protected]:${repo}.git to ${targetpath}`);
child_process.execSync(`git clone ${getBranch(branch)} [email protected]:${repo}.git ${targetpath}`);

}
console.log('Clone successful');
}
Expand All @@ -56,40 +55,40 @@ function cloneRepo(targetpath, repo, branch, useHttp = true) {
* @param {string} branch
* @returns {string}
*/
function getBranch(branch) {
function getBranch (branch) {
return branch ? `-b ${branch}` : '';
}

function handleConfig() {
if(fs.existsSync(configSourcePath)) {
function handleConfig () {
if (fs.existsSync(configSourcePath)) {
try {
fs.copyFile(configSourcePath, configDestPath);
console.log('Successfully set config from content repo!');
} catch (err) {
console.error(err)
console.error(err);
}
}
}

function handleContent() {
if(fs.existsSync(contentSourcePath)) {
function handleContent () {
if (fs.existsSync(contentSourcePath)) {
try {
fs.copySync(contentSourcePath, contentDestPath, { overwrite: true })
console.log('Successfully set content from content repo!')
fs.copySync(contentSourcePath, contentDestPath, { overwrite: true });
console.log('Successfully set content from content repo!');
} catch (err) {
console.error(err)
console.error(err);
}
}
}

function handlePublic() {
if(fs.existsSync(publicSourcePath)) {
function handlePublic () {
if (fs.existsSync(publicSourcePath)) {
try {
fs.copySync(publicSourcePath, publicDestPath, { overwrite: true })
console.log('Successfully set public folder from content repo!')
console.log('Public folder contents: ', fs.readdirSync(publicDestPath))
fs.copySync(publicSourcePath, publicDestPath, { overwrite: true });
console.log('Successfully set public folder from content repo!');
console.log('Public folder contents: ', fs.readdirSync(publicDestPath));
} catch (err) {
console.error(err)
console.error(err);
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"test": "concurrently --kill-others -s first \"npm run start\" \"npm run cy:run\"",
"test": "concurrently -c \"auto\" --names \"RUN,TEST\" --kill-others -s first --hide \"0\" \"npm run start\" \"npm run cy:run\"",
"test:watch": "vitest --reporter verbose --globals --coverage",
"lint-all": "eslint .",
"lint-fix-all": "eslint . --fix",
Expand Down

0 comments on commit 1994b0c

Please sign in to comment.