chore(cypress): speed up seeding when testing (#50825)

This commit is contained in:
Oliver Eyton-Williams
2023-06-29 18:18:10 +02:00
committed by GitHub
parent 17c5c8e035
commit 8d12376931
22 changed files with 63 additions and 37 deletions

View File

@@ -2,6 +2,10 @@ const { execSync } = require('child_process');
const { existsSync } = require('fs');
const { defineConfig } = require('cypress');
function seed(args = []) {
return execSync('node tools/scripts/seed/seed-demo-user ' + args.join(' '));
}
module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:8000',
@@ -31,6 +35,9 @@ module.exports = defineConfig({
execSync('pnpm run build:curriculum');
}
});
on('task', {
seed
});
config.env.API_LOCATION = 'http://localhost:3000';
return config;

View File

@@ -1,7 +1,7 @@
describe('CodeAlly cert challenge', function () {
describe('before completing the project', function () {
before(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
cy.visit(
'/learn/relational-database/build-a-celestial-bodies-database-project/build-a-celestial-bodies-database'
@@ -19,7 +19,7 @@ describe('CodeAlly cert challenge', function () {
describe('after completing the project', function () {
before(() => {
cy.exec('pnpm run seed:certified-user');
cy.task('seed', ['certified-user']);
cy.login();
cy.visit(
'/learn/relational-database/build-a-celestial-bodies-database-project/build-a-celestial-bodies-database'

View File

@@ -21,7 +21,7 @@ function getCompletedIds(completedChallenges: ChallengeData[]): string[] {
describe('failed update flushing', function () {
before(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});

View File

@@ -10,7 +10,7 @@ const editorElements = {
describe('multifileCertProjects', function () {
before(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});
@@ -39,7 +39,7 @@ describe('multifileCertProjects', function () {
it('should save using ctrl+s hotkey and persist through navigation', function () {
// since rapid clicks will cause the save requests to be ignored, we have to
// purge the db:
cy.exec('pnpm run seed');
cy.task('seed');
// and the redux store:
cy.reload();
cy.get(editorElements.container).find(editorElements.editor).click();

View File

@@ -14,7 +14,7 @@ const challenge2 = {
describe('submitting a challenge', () => {
before(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});

View File

@@ -1,6 +1,6 @@
describe('progress bar', () => {
beforeEach(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});

View File

@@ -64,7 +64,7 @@ const pythonProjects = {
describe('project submission', () => {
beforeEach(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});
// NOTE: this will fail once challenge tests are added.

View File

@@ -1,6 +1,6 @@
describe('Donate page', () => {
beforeEach(() => {
cy.exec('pnpm run seed -- --donor');
cy.task('seed', ['--donor']);
cy.login();
});

View File

@@ -1,12 +1,12 @@
describe('Donate page', () => {
before(() => {
cy.clearCookies();
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});
after(() => {
cy.exec('pnpm run seed');
cy.task('seed');
});
const projects = [

View File

@@ -46,7 +46,7 @@ describe('Default Navigation Menu', () => {
describe('Authenticated Navigation Menu', () => {
before(() => {
cy.clearCookies();
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
cy.get(navigationItems['toggle-button']).should('be.visible').click();
});
@@ -68,7 +68,7 @@ describe('Authenticated Navigation Menu', () => {
describe('Authenticated User Sign Out', () => {
before(() => {
cy.clearCookies();
cy.exec('pnpm run seed');
cy.task('seed');
});
beforeEach(() => {
cy.login();
@@ -94,7 +94,7 @@ describe('Authenticated User Sign Out', () => {
describe('Donor Navigation Menu', () => {
before(() => {
cy.clearCookies();
cy.exec('pnpm run seed -- --donor');
cy.task('seed', ['--donor']);
cy.login();
cy.visit('/donate');
});

View File

@@ -4,7 +4,7 @@ const introPageSelectors = {
describe('Certification intro page', () => {
before(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});

View File

@@ -29,7 +29,7 @@ const projects = {
describe('Front End Development Libraries Superblock', () => {
before(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
cy.visit('/learn/front-end-development-libraries');
});
@@ -41,7 +41,7 @@ describe('Front End Development Libraries Superblock', () => {
});
describe('After submitting all 5 projects', () => {
before(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
cy.visit('/settings');
cy.setPrivacyTogglesToPublic();

View File

@@ -3,7 +3,7 @@ import '@testing-library/cypress/add-commands';
describe('Settings certifications area', () => {
describe('initially', () => {
before(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});
@@ -23,7 +23,7 @@ describe('Settings certifications area', () => {
describe('after isHonest', () => {
before(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});

View File

@@ -1,6 +1,6 @@
describe('Email input field', () => {
beforeEach(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
cy.visit('/settings');
});

View File

@@ -1,7 +1,7 @@
describe('User token widget on settings page,', function () {
describe('initially', function () {
beforeEach(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});
@@ -15,7 +15,7 @@ describe('User token widget on settings page,', function () {
describe('after creating token', function () {
beforeEach(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
cy.visit(
'/learn/relational-database/learn-bash-by-building-a-boilerplate/build-a-boilerplate'

View File

@@ -2,7 +2,7 @@ const certifiedUser = '/certification/certifieduser/responsive-web-design';
describe('A certification,', function () {
before(() => {
cy.exec('pnpm run seed:certified-user');
cy.task('seed', ['certified-user']);
});
describe('while viewing your own,', function () {

View File

@@ -1,11 +1,11 @@
describe('Top contributor in user profile', () => {
before(() => {
cy.clearCookies();
cy.exec('pnpm run seed -- --top-contributor');
cy.task('seed', ['--top-contributor']);
});
after(() => {
cy.exec('pnpm run seed');
cy.task('seed');
});
beforeEach(() => {

View File

@@ -1,7 +1,7 @@
describe('Public profile certifications', () => {
context('Signed in user viewing their own public profile', () => {
before(() => {
cy.exec('pnpm run seed:certified-user');
cy.task('seed', ['certified-user']);
});
beforeEach(() => {

View File

@@ -8,7 +8,7 @@ describe('Privacy terms', () => {
}).as('updatePrivacyTerms');
// Seed dev user with `acceptedPrivacyTerms` unset
cy.exec('pnpm run seed -- --unset-privacy-terms');
cy.task('seed', ['--unset-privacy-terms']);
// Go to the homepage and log in manually so we can assert the following:
// 1. Redirection to /email-sign-up works properly
// 2. The /update-privacy-terms has not been requested
@@ -37,7 +37,7 @@ describe('Privacy terms', () => {
}).as('updatePrivacyTerms');
// Seed dev user with `acceptedPrivacyTerms` unset
cy.exec('pnpm run seed -- --unset-privacy-terms');
cy.task('seed', ['--unset-privacy-terms']);
// Go to the homepage and log in manually so we can assert the following:
// 1. Redirection to /email-sign-up works properly
// 2. The /update-privacy-terms has not been requested

View File

@@ -1,6 +1,6 @@
describe('Report User', () => {
beforeEach(() => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
});
it('should be possible to report a user from their profile page', () => {

View File

@@ -1,6 +1,6 @@
describe('Donate page', () => {
it('Donation ', () => {
cy.exec('pnpm run seed');
cy.task('seed');
cy.login();
cy.visit('/donate');
cy.get('.donation-elements', { timeout: 10000 }).within(() => {

View File

@@ -4,7 +4,28 @@ require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') });
const { MongoClient, ObjectId } = require('mongodb');
const fullyCertifiedUser = require('./certified-user-data');
const envVariables = process.argv;
const args = process.argv.slice(2);
const allowedArgs = [
'--donor',
'--top-contributor',
'--unset-privacy-terms',
'certified-user'
];
// Check for invalid arguments
args.forEach(arg => {
if (!allowedArgs.includes(arg))
throw new Error(
`Invalid argument ${arg}. Allowed arguments are ${allowedArgs.join(', ')}`
);
});
if (args.includes('certified-user') && args.length > 1) {
throw new Error(
`Invalid arguments. When using 'certified-user', no other arguments are allowed.`
);
}
const log = debug('fcc:tools:seedLocalAuthUser');
const { MONGOHQ_URL } = process.env;
@@ -36,9 +57,7 @@ const demoUser = {
name: 'Development User',
location: '',
picture: '',
acceptedPrivacyTerms: envVariables.includes('--unset-privacy-terms')
? null
: true,
acceptedPrivacyTerms: args.includes('--unset-privacy-terms') ? null : true,
sendQuincyEmail: false,
currentChallengeId: '',
isHonest: false,
@@ -62,7 +81,7 @@ const demoUser = {
isCollegeAlgebraPyCertV8: false,
completedChallenges: [],
portfolio: [],
yearsTopContributor: envVariables.includes('--top-contributor')
yearsTopContributor: args.includes('--top-contributor')
? ['2017', '2018', '2019']
: [],
rand: 0.6126749173148205,
@@ -82,7 +101,7 @@ const demoUser = {
badges: {
coreTeam: []
},
isDonating: envVariables.includes('--donor'),
isDonating: args.includes('--donor'),
emailAuthLinkTTL: null,
emailVerifyTTL: null,
keyboardShortcuts: true,
@@ -183,7 +202,7 @@ const dropUsers = async function () {
const run = async () => {
await dropUserTokens();
await dropUsers();
if (process.argv[2] === 'certified-user') {
if (args.includes('certified-user')) {
await user.insertOne(fullyCertifiedUser);
await user.insertOne(blankUser);
} else {