Rewrite Oclif Test in Esmock
Budget: €8 – €30 EUR
i have this oclif test
import { expect, test } from '@oclif/test';
import * as Check from '../../src/commands/check';
import * as Helpers from '../../src/helpers';
const command = 'publish';
const env = 'preprod';
const subgraph = 'subgraph-qa-one';
const routingUrl = '';
const schemaPath = './test/commands/schemas/publish/';
const args = [command, '--env', env, '--name', subgraph, '--routing-url', routingUrl];
describe('gql-cli publish success', () => {
test
.stub(Check.default, 'run', async () => null)
.stub(Helpers, 'getApolloClient', () => ({
mutate: async () => ({
data: {
schemaDeploy: {
status: 'SUCCEED',
},
},
}),
}))
.stdout()
.command([...args, '--schema', `${schemaPath}/success-unchanged.graphql`])
.it('Successfully runs publish command', (ctx) => {
expect(ctx.stdout).to.contain('SUCCEED');
});
});
describe('gql-cli publish failure', () => {
test
.stub(Check.default, 'run', async () => null)
.stub(Helpers, 'getApolloClient', () => ({
mutate: async () => ({
data: {
schemaDeploy: {
status: 'FAILED',
errors: [
{
code: 'CODE1',
message: 'Error Message 1',
},
{
code: 'CODE2',
message: 'Error Message 2',
},
],
},
},
}),
}))
.stderr()
.command([...args, '--schema', `${schemaPath}/error-operation.graphql`])
.catch(() => {})
.it('Failed publish with errors', (ctx) => {
expect(ctx.stderr).to.contain('Deploy Errors');
expect(ctx.stderr).to.contain('Error Message 1');
expect(ctx.stderr).to.contain('CODE2');
});
});
as oclif does not support stub anymore i want to write it in esmock and for assertion chai and mocha. help me to write it
import { expect, test } from '@oclif/test';
import * as Check from '../../src/commands/check';
import * as Helpers from '../../src/helpers';
const command = 'publish';
const env = 'preprod';
const subgraph = 'subgraph-qa-one';
const routingUrl = '';
const schemaPath = './test/commands/schemas/publish/';
const args = [command, '--env', env, '--name', subgraph, '--routing-url', routingUrl];
describe('gql-cli publish success', () => {
test
.stub(Check.default, 'run', async () => null)
.stub(Helpers, 'getApolloClient', () => ({
mutate: async () => ({
data: {
schemaDeploy: {
status: 'SUCCEED',
},
},
}),
}))
.stdout()
.command([...args, '--schema', `${schemaPath}/success-unchanged.graphql`])
.it('Successfully runs publish command', (ctx) => {
expect(ctx.stdout).to.contain('SUCCEED');
});
});
describe('gql-cli publish failure', () => {
test
.stub(Check.default, 'run', async () => null)
.stub(Helpers, 'getApolloClient', () => ({
mutate: async () => ({
data: {
schemaDeploy: {
status: 'FAILED',
errors: [
{
code: 'CODE1',
message: 'Error Message 1',
},
{
code: 'CODE2',
message: 'Error Message 2',
},
],
},
},
}),
}))
.stderr()
.command([...args, '--schema', `${schemaPath}/error-operation.graphql`])
.catch(() => {})
.it('Failed publish with errors', (ctx) => {
expect(ctx.stderr).to.contain('Deploy Errors');
expect(ctx.stderr).to.contain('Error Message 1');
expect(ctx.stderr).to.contain('CODE2');
});
});
as oclif does not support stub anymore i want to write it in esmock and for assertion chai and mocha. help me to write it