Skip to content

Commit

Permalink
chore: fixed test and mockversion
Browse files Browse the repository at this point in the history
  • Loading branch information
abhilash-sivan committed Nov 18, 2024
1 parent c01e2d2 commit 5338879
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ process.on('SIGTERM', () => {
process.exit(0);
});

require('./mockVersion');
require('../../../..')();

const cls = require('../../../../../core/src/tracing/cls');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ process.on('SIGTERM', () => {
process.exit(0);
});

require('./mockVersion');
require('../../../..')();

const cls = require('../../../../../core/src/tracing/cls');

const express = require('express');
const morgan = require('morgan');
const graphqlSubscriptions = require('graphql-subscriptions-v2');
const graphqlSubscriptions = require('graphql-subscriptions');
const port = require('../../../test_util/app-port')();

const pubsub = new graphqlSubscriptions.PubSub();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* (c) Copyright IBM Corp. 2024
*/

'use strict';

const mock = require('mock-require');
const hook = require('../../../../../core/src/util/hook');

const GRAPHQL_SUBSCRIPTIONS_VERSION = process.env.GRAPHQL_SUBSCRIPTIONS_VERSION;
const GRAPHQL_SUBSCRIPTIONS_REQUIRE =
process.env.GRAPHQL_SUBSCRIPTIONS_VERSION === 'latest'
? 'graphql-subscriptions'
: `graphql-subscriptions-${GRAPHQL_SUBSCRIPTIONS_VERSION}`;

if (GRAPHQL_SUBSCRIPTIONS_REQUIRE !== 'graphql-subscriptions') {
mock('graphql-subscriptions', GRAPHQL_SUBSCRIPTIONS_REQUIRE);
}

const originalOnFileLoad = hook.onFileLoad;
hook.onFileLoad = function onFileLoad() {
if (arguments[0].source === '\\/graphql-subscriptions\\/dist\\/pubsub-async-iterator\\.js') {
const str = arguments[0].source.replace('graphql-subscriptions', GRAPHQL_SUBSCRIPTIONS_REQUIRE);
const reg = new RegExp(str, '');
arguments[0] = reg;
return originalOnFileLoad.apply(this, arguments);
}

return originalOnFileLoad.apply(this, arguments);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config = require('../../../../../core/test/config');
const ProcessControls = require('../../../test_util/ProcessControls');
const globalAgent = require('../../../globalAgent');

const mochaSuiteFn = supportedVersion(process.versions.node) ? describe.only : describe.skip;
const mochaSuiteFn = supportedVersion(process.versions.node) ? describe : describe.skip;

['latest', 'v2'].forEach(version => {
mochaSuiteFn(`tracing/graphql-subscriptions@${version} - PubSub/async iterator (pull before push)`, function () {
Expand All @@ -24,7 +24,10 @@ const mochaSuiteFn = supportedVersion(process.versions.node) ? describe.only : d

before(async () => {
controls = new ProcessControls({
appPath: version === 'v2' ? path.join(__dirname, 'app_v2') : path.join(__dirname, 'app'),
appPath: version === 'latest' ? path.join(__dirname, 'app') : path.join(__dirname, 'app_v2'),
env: {
GRAPHQL_SUBSCRIPTIONS_VERSION: version
},
useGlobalAgent: true
});

Expand Down

0 comments on commit 5338879

Please sign in to comment.