Cypress improvements, move mkcert back to command line

This commit is contained in:
Jamie Curnow committed 2026-05-19 08:51:52 +10:00
1 parent f53bf88f4d
commit 11955e5dff
10 files changed
+133 -210

No files matched your search

+20 -25
View File
@@ -10,7 +10,6 @@
//
import 'cypress-wait-until';
import { createCA, createCert } from 'mkcert';
Cypress.Commands.add('randomString', (length) => {
let result = '';
@@ -49,14 +48,16 @@ Cypress.Commands.add("validateSwaggerFile", (url, savePath) => {
* @param {*} data The API response data to check against the swagger schema
*/
Cypress.Commands.add('validateSwaggerSchema', (method, code, path, data) => {
cy.task('validateSwaggerSchema', {
file: cy.env('swaggerBase'),
endpoint: path,
method: method,
statusCode: code,
responseSchema: data,
verbose: true
}).should('equal', null);
cy.env(['swaggerBase']).then(({ swaggerBase }) => {
cy.task('validateSwaggerSchema', {
file: swaggerBase,
endpoint: path,
method: method,
statusCode: code,
responseSchema: data,
verbose: true
}).should('equal', null);
});
});
Cypress.Commands.add('createInitialUser', (defaultUser) => {
@@ -156,21 +157,15 @@ Cypress.Commands.add('waitForCertificateStatus', (token, certID, expected, timeo
// Creates CA files for testing, if they already exist they will be deleted
// and recreated with the same content. This is to ensure that the files exist
// for testing and are in a known state.
Cypress.Commands.add('createCustomCerts', async () => {
const ca = await createCA({
organization: "NPM CA",
countryCode: "AU",
state: "QLD",
locality: "Brisbane",
validity: 365
Cypress.Commands.add('createCustomCerts', () => {
cy.task('getFixturesFolder').then((fixturesFolder) => {
cy.exec(`mkcert -cert-file=${fixturesFolder}/test.example.com.pem -key-file=${fixturesFolder}/test.example.com-key.pem test.example.com`)
.then((result) => {
expect(result.exitCode).to.eq(0);
// Install CA
cy.exec('mkcert -install').then((result) => {
expect(result.exitCode).to.eq(0);
});
});
});
const cert = await createCert({
ca: { key: ca.key, cert: ca.cert },
domains: ["test.example.com"],
validity: 365
});
cy.writeFile(`${config.fixturesFolder}/test.example.com.pem`, cert.cert);
cy.writeFile(`${config.fixturesFolder}/test.example.com-key.pem`, cert.key);
});
+100
View File
@@ -0,0 +1,100 @@
import fs from "node:fs";
import FormData from "form-data";
import Client from "./client.mjs";
import logger from "./logger.mjs";
export default (config) => {
logger("Client Ready using", config.baseUrl);
return {
/**
* @param {object} options
* @param {string} options.path API path
* @param {string} [options.token] JWT
* @param {bool} [options.returnOnError] If true, will return instead of throwing errors
* @returns {string}
*/
backendApiGet: (options) => {
const api = new Client(config);
api.setToken(options.token);
return api.request("get", options.path, options.returnOnError || false);
},
/**
* @param {object} options
* @param {string} options.token JWT
* @param {string} options.path API path
* @param {object} options.data
* @param {bool} [options.returnOnError] If true, will return instead of throwing errors
* @returns {string}
*/
backendApiPost: (options) => {
const api = new Client(config);
api.setToken(options.token);
return api.request(
"post",
options.path,
options.returnOnError || false,
options.data,
);
},
/**
* @param {object} options
* @param {string} options.token JWT
* @param {string} options.path API path
* @param {object} options.files
* @param {bool} [options.returnOnError] If true, will return instead of throwing errors
* @returns {string}
*/
backendApiPostFiles: (options) => {
const api = new Client(config);
api.setToken(options.token);
const form = new FormData();
for (const [key, value] of Object.entries(options.files)) {
form.append(
key,
fs.createReadStream(`${config.fixturesFolder}/${value}`),
);
}
return api.postForm(options.path, form, options.returnOnError || false);
},
/**
* @param {object} options
* @param {string} options.token JWT
* @param {string} options.path API path
* @param {object} options.data
* @param {bool} [options.returnOnError] If true, will return instead of throwing errors
* @returns {string}
*/
backendApiPut: (options) => {
const api = new Client(config);
api.setToken(options.token);
return api.request(
"put",
options.path,
options.returnOnError || false,
options.data,
);
},
/**
* @param {object} options
* @param {string} options.token JWT
* @param {string} options.path API path
* @param {bool} [options.returnOnError] If true, will return instead of throwing errors
* @returns {string}
*/
backendApiDelete: (options) => {
const api = new Client(config);
api.setToken(options.token);
return api.request(
"delete",
options.path,
options.returnOnError || false,
);
},
};
};