Update cypress mock methods
This commit is contained in:
parent
fbcd5dcd6d
commit
a17db3f289
|
|
@ -1,9 +1,21 @@
|
||||||
import {defineConfig} from 'cypress';
|
import {defineConfig} from 'cypress';
|
||||||
|
import {readFileSync} from "fs";
|
||||||
|
import {resolve} from "path";
|
||||||
export default defineConfig( {
|
export default defineConfig( {
|
||||||
e2e: {
|
e2e: {
|
||||||
"baseUrl": "http://localhost:8000",
|
"baseUrl": "http://localhost:8000",
|
||||||
specPattern: 'cypress/e2e/e2e/**/*.{spec,cy}.{js,ts}',
|
specPattern: 'cypress/e2e/e2e/**/*.{spec,cy}.{js,ts}',
|
||||||
supportFile: 'cypress/support/e2e.ts',
|
supportFile: 'cypress/support/e2e.ts',
|
||||||
|
setupNodeEvents(on, config) {
|
||||||
|
on('task', {
|
||||||
|
getSchema() {
|
||||||
|
return readFileSync(
|
||||||
|
resolve(__dirname, '../server/schema.graphql'),
|
||||||
|
'utf8'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"videoUploadOnPasses": false,
|
"videoUploadOnPasses": false,
|
||||||
"reporter": "junit",
|
"reporter": "junit",
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ declare global {
|
||||||
// import 'cypress-graphql-mock';
|
// import 'cypress-graphql-mock';
|
||||||
import mocks from '../fixtures/mocks';
|
import mocks from '../fixtures/mocks';
|
||||||
import {addMocksToSchema} from "@graphql-tools/mock";
|
import {addMocksToSchema} from "@graphql-tools/mock";
|
||||||
import {graphql} from "graphql";
|
import {graphql, GraphQLError} from "graphql";
|
||||||
|
|
||||||
Cypress.Commands.add('apolloLogin', (username, password) => {
|
Cypress.Commands.add('apolloLogin', (username, password) => {
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|
@ -150,6 +150,29 @@ Cypress.Commands.add('mockGraphql', (options?: any) => {
|
||||||
const {operationName, query, variables} = req.body;
|
const {operationName, query, variables} = req.body;
|
||||||
const rootValue = getRootValue(currentOperations, operationName, variables);
|
const rootValue = getRootValue(currentOperations, operationName, variables);
|
||||||
|
|
||||||
|
if (!rootValue) {
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
// Additional checks here because of transpilation.
|
||||||
|
// We will lose instanceof if we are not using specific babel plugin, or using pure TS to compile front-end
|
||||||
|
rootValue instanceof GraphQLError ||
|
||||||
|
rootValue.constructor === GraphQLError ||
|
||||||
|
rootValue.constructor.name === "GraphQLError"
|
||||||
|
) {
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(
|
||||||
|
() =>
|
||||||
|
new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
data: {},
|
||||||
|
errors: [rootValue]
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
graphql({
|
graphql({
|
||||||
schema: schemaWithMocks,
|
schema: schemaWithMocks,
|
||||||
source: query,
|
source: query,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue