Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Oct 9, 2024
1 parent dfdd354 commit 17cf69f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
11 changes: 11 additions & 0 deletions integrationTests/node/index.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const assert = require('assert');
const expect = require('expect');
const { readFileSync } = require('fs');

const {
experimentalExecuteIncrementally,
graphqlSync,
isSource,
parse,
} = require('graphql');
const { buildSchema } = require('graphql/utilities');
Expand Down Expand Up @@ -52,3 +54,12 @@ result = experimentalExecuteIncrementally({

assert(result.errors?.[0] !== undefined);
assert(!result.errors[0].message.includes('is not defined'));

// test instanceOf without development condition
class Source {
get [Symbol.toStringTag]() {
return 'Source';
}
}
const source = new Source();
expect(isSource(source)).to.equal(false);
11 changes: 11 additions & 0 deletions integrationTests/node/index.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable simple-import-sort/imports */
import assert from 'assert';
import expect from 'expect';
import { readFileSync } from 'fs';

import {
experimentalExecuteIncrementally,
graphqlSync,
isSource,
parse,
} from 'graphql-esm';
import { buildSchema } from 'graphql-esm/utilities';
Expand Down Expand Up @@ -53,3 +55,12 @@ result = experimentalExecuteIncrementally({

assert(result.errors?.[0] !== undefined);
assert(!result.errors[0].message.includes('is not defined'));

// test instanceOf without development condition
class Source {
get [Symbol.toStringTag]() {
return 'Source';
}
}
const source = new Source();
expect(isSource(source)).to.equal(false);
15 changes: 15 additions & 0 deletions integrationTests/node/instanceOfForDevelopment.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const expect = require('expect');

const { isSource } = require('graphql');

class Source {
get [Symbol.toStringTag]() {
return 'Source';
}
}
const source = new Source();
expect(() =>
isSource(source).to.throw(
/^Cannot use Source "{}" from another module or realm./m,
),
);
16 changes: 16 additions & 0 deletions integrationTests/node/instanceOfForDevelopment.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable simple-import-sort/imports */
import expect from 'expect';

import { isSource } from 'graphql-esm';

class Source {
get [Symbol.toStringTag]() {
return 'Source';
}
}
const source = new Source();
expect(() =>
isSource(source).to.throw(
/^Cannot use Source "{}" from another module or realm./m,
),
);
18 changes: 10 additions & 8 deletions integrationTests/node/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const nodeVersions = graphqlPackageJSON.engines.node
for (const version of nodeVersions) {
console.log(`Testing on node@${version} ...`);

childProcess.execSync(
`docker run --rm --volume "$PWD":/usr/src/app -w /usr/src/app node:${version}-slim node ./index.cjs`,
{ stdio: 'inherit' },
);
for (const test of ['index', 'instanceOfForDevelopment']) {
childProcess.execSync(
`docker run --rm --volume "$PWD":/usr/src/app -w /usr/src/app node:${version}-slim node ./${test}.cjs`,
{ stdio: 'inherit' },
);

childProcess.execSync(
`docker run --rm --volume "$PWD":/usr/src/app -w /usr/src/app node:${version}-slim node ./index.mjs`,
{ stdio: 'inherit' },
);
childProcess.execSync(
`docker run --rm --volume "$PWD":/usr/src/app -w /usr/src/app node:${version}-slim node ./${test}.mjs`,
{ stdio: 'inherit' },
);
}
}

0 comments on commit 17cf69f

Please sign in to comment.