Update cypress mock methods
This commit is contained in:
parent
fbcd5dcd6d
commit
a17db3f289
|
|
@ -1,9 +1,21 @@
|
|||
import {defineConfig} from 'cypress';
|
||||
import {readFileSync} from "fs";
|
||||
import {resolve} from "path";
|
||||
export default defineConfig( {
|
||||
e2e: {
|
||||
"baseUrl": "http://localhost:8000",
|
||||
specPattern: 'cypress/e2e/e2e/**/*.{spec,cy}.{js,ts}',
|
||||
supportFile: 'cypress/support/e2e.ts',
|
||||
setupNodeEvents(on, config) {
|
||||
on('task', {
|
||||
getSchema() {
|
||||
return readFileSync(
|
||||
resolve(__dirname, '../server/schema.graphql'),
|
||||
'utf8'
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
"videoUploadOnPasses": false,
|
||||
"reporter": "junit",
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ declare global {
|
|||
// import 'cypress-graphql-mock';
|
||||
import mocks from '../fixtures/mocks';
|
||||
import {addMocksToSchema} from "@graphql-tools/mock";
|
||||
import {graphql} from "graphql";
|
||||
import {graphql, GraphQLError} from "graphql";
|
||||
|
||||
Cypress.Commands.add('apolloLogin', (username, password) => {
|
||||
const payload = {
|
||||
|
|
@ -150,6 +150,29 @@ Cypress.Commands.add('mockGraphql', (options?: any) => {
|
|||
const {operationName, query, variables} = req.body;
|
||||
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({
|
||||
schema: schemaWithMocks,
|
||||
source: query,
|
||||
|
|
|
|||
Loading…
Reference in New Issue