Skip to content

Commit d3e3a11

Browse files
committed
Fix tests and cleanup
1 parent f8c57bf commit d3e3a11

4 files changed

Lines changed: 10 additions & 135 deletions

File tree

packages/node-require/src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import { isSome } from '@graphql-tools/utils';
1111

1212
const VALID_EXTENSIONS = ['graphql', 'graphqls', 'gql', 'gqls'];
1313

14-
function handleModule(m: NodeModule, filename: string) {
15-
console.log(m, filename);
14+
export function handleModule(m: NodeModule, filename: string) {
1615
const sources = loadTypedefsSync(filename, {
1716
loaders: [new GraphQLFileLoader()],
1817
});
@@ -22,9 +21,9 @@ function handleModule(m: NodeModule, filename: string) {
2221
m.exports = mergedDoc;
2322
}
2423

25-
export function registerGraphQLExtensions(require: NodeRequire) {
24+
export function registerGraphQLExtensions(nodeRequire: NodeRequire) {
2625
for (const ext of VALID_EXTENSIONS) {
27-
require.extensions[`.${ext}`] = handleModule;
26+
nodeRequire.extensions[`.${ext}`] = handleModule;
2827
}
2928
}
3029

packages/node-require/test/node-require.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import '../src';
1+
import { handleModule } from '../src';
22
import { print } from 'graphql';
33
import { readFileSync } from 'fs';
4+
import { join } from 'path';
45

56
describe('GraphQL Node Import', () => {
6-
it.skip('should import correct definitions', () => {
7-
console.log(require.main);
7+
it('should import correct definitions', () => {
88
const filePath = './fixtures/test.graphql';
9-
const typeDefs = require(filePath);
9+
const m: any = {};
10+
handleModule(m, join(__dirname, filePath));
11+
const typeDefs = m.exports;
1012
expect(print(typeDefs).replace(/\s\s+/g, ' ')).toBe(
1113
readFileSync(require.resolve(filePath), 'utf8').replace(/\s\s+/g, ' ')
1214
);

packages/resolvers-composition/yarn.lock

Lines changed: 0 additions & 126 deletions
This file was deleted.

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2715,7 +2715,7 @@
27152715
dependencies:
27162716
"@types/unist" "*"
27172717

2718-
"@types/micromatch@latest":
2718+
"@types/micromatch@^4.0.1", "@types/micromatch@latest":
27192719
version "4.0.1"
27202720
resolved "https://registry.yarnpkg.com/@types/micromatch/-/micromatch-4.0.1.tgz#9381449dd659fc3823fd2a4190ceacc985083bc7"
27212721
integrity sha1-k4FEndZZ/Dgj/SpBkM6syYUIO8c=

0 commit comments

Comments
 (0)