From 310d7ad2b1ea9f096eb1d333dde52332c9e2f7e2 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Fri, 18 Jun 2021 18:07:50 +0300 Subject: [PATCH] integrationTests: Add test for webpack Motivated by #3178 --- .eslintrc.yml | 1 + integrationTests/integration-test.js | 4 ++++ integrationTests/webpack/entry.js | 13 +++++++++++++ integrationTests/webpack/package.json | 11 +++++++++++ integrationTests/webpack/test.js | 14 ++++++++++++++ integrationTests/webpack/webpack.config.json | 7 +++++++ 6 files changed, 50 insertions(+) create mode 100644 integrationTests/webpack/entry.js create mode 100644 integrationTests/webpack/package.json create mode 100644 integrationTests/webpack/test.js create mode 100644 integrationTests/webpack/webpack.config.json diff --git a/.eslintrc.yml b/.eslintrc.yml index 39c677e87a..e2a41718db 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -630,6 +630,7 @@ overrides: rules: node/no-sync: off node/no-missing-require: [error, { allowModules: ['graphql'] }] + import/no-commonjs: off import/no-nodejs-modules: off no-console: off - files: 'benchmark/**' diff --git a/integrationTests/integration-test.js b/integrationTests/integration-test.js index df27b801a7..a2fe883b26 100644 --- a/integrationTests/integration-test.js +++ b/integrationTests/integration-test.js @@ -42,4 +42,8 @@ describe('Integration Tests', () => { it('Should work on all supported node versions', () => { testOnNodeProject('node'); }).timeout(40000); + + it('Should be compatible with Webpack', () => { + testOnNodeProject('webpack'); + }).timeout(40000); }); diff --git a/integrationTests/webpack/entry.js b/integrationTests/webpack/entry.js new file mode 100644 index 0000000000..8f51030c5d --- /dev/null +++ b/integrationTests/webpack/entry.js @@ -0,0 +1,13 @@ +'use strict'; + +const { buildSchema, graphqlSync } = require('graphql'); + +const schema = buildSchema('type Query { hello: String }'); + +const result = graphqlSync({ + schema, + source: '{ hello }', + rootValue: { hello: 'world' }, +}); + +module.exports = { result }; diff --git a/integrationTests/webpack/package.json b/integrationTests/webpack/package.json new file mode 100644 index 0000000000..dac5558ff4 --- /dev/null +++ b/integrationTests/webpack/package.json @@ -0,0 +1,11 @@ +{ + "private": true, + "scripts": { + "test": "webpack && node test.js" + }, + "dependencies": { + "graphql": "file:../graphql.tgz", + "webpack": "5.x.x", + "webpack-cli": "4.x.x" + } +} diff --git a/integrationTests/webpack/test.js b/integrationTests/webpack/test.js new file mode 100644 index 0000000000..40c22233d4 --- /dev/null +++ b/integrationTests/webpack/test.js @@ -0,0 +1,14 @@ +'use strict'; + +const assert = require('assert'); + +// eslint-disable-next-line node/no-missing-require +const { result } = require('./dist/main.js'); + +assert.deepStrictEqual(result, { + data: { + __proto__: null, + hello: 'world', + }, +}); +console.log('Test script: Got correct result from Webpack bundle!'); diff --git a/integrationTests/webpack/webpack.config.json b/integrationTests/webpack/webpack.config.json new file mode 100644 index 0000000000..830b2bd52d --- /dev/null +++ b/integrationTests/webpack/webpack.config.json @@ -0,0 +1,7 @@ +{ + "mode": "production", + "entry": "./entry.js", + "output": { + "libraryTarget": "commonjs2" + } +}