From 1994b0c2c5c8dabbc284bdcbc1d469574513e3d1 Mon Sep 17 00:00:00 2001 From: Mocca101 NB <49754596+Mocca101@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:25:23 +0200 Subject: [PATCH] Attempt at making tests work on github actions Also: more concise deubg messages for tests --- cypress.config.ts | 11 ++++++- cypress/e2e/MainToOtherPages.cy.ts | 30 ++++++++++++------ deployment/loadContent.mjs | 51 +++++++++++++++--------------- package.json | 2 +- 4 files changed, 57 insertions(+), 37 deletions(-) diff --git a/cypress.config.ts b/cypress.config.ts index 7faa6ceb..95c79a2c 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -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; + } + }); + } } }); diff --git a/cypress/e2e/MainToOtherPages.cy.ts b/cypress/e2e/MainToOtherPages.cy.ts index ee142dfc..bc35f140 100644 --- a/cypress/e2e/MainToOtherPages.cy.ts +++ b/cypress/e2e/MainToOtherPages.cy.ts @@ -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') @@ -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'); + } }); }); diff --git a/deployment/loadContent.mjs b/deployment/loadContent.mjs index 59f01123..2947d03e 100644 --- a/deployment/loadContent.mjs +++ b/deployment/loadContent.mjs @@ -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(); @@ -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 git@github.com:${repo}.git to ${targetpath}`); child_process.execSync(`git clone ${getBranch(branch)} git@github.com:${repo}.git ${targetpath}`); - } console.log('Clone successful'); } @@ -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); } } } diff --git a/package.json b/package.json index 5e0f1711..8b60d159 100644 --- a/package.json +++ b/package.json @@ -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",