Skip to content

Commit

Permalink
ESM CJS + Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Mar 31, 2020
1 parent d9ac572 commit b7d6a88
Show file tree
Hide file tree
Showing 26 changed files with 1,195 additions and 1,162 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Expand Up @@ -4,6 +4,7 @@ parserOptions:
env:
es6: true
node: true
jest: true
plugins:
- import

Expand Down
3 changes: 0 additions & 3 deletions .travis.yml
Expand Up @@ -31,8 +31,5 @@ script:
- npm install graphql@$GRAPHQL_VERSION
- npm run testonly:cover

after_success:
- npm run coverage

# Allow Travis tests to run in containers.
sudo: false
19 changes: 19 additions & 0 deletions jest.config.js
@@ -0,0 +1,19 @@
const { resolve } = require('path');
const CI = !!process.env.CI;

module.exports = {
transform: { '^.+\\.tsx?$': 'ts-jest' },
testEnvironment: 'node',
rootDir: process.cwd(),
globals: {
'ts-jest': {
diagnostics: false,
tsConfig: 'tsconfig.json'
}
},
restoreMocks: true,
reporters: ['default'],
modulePathIgnorePatterns: ['dist'],
collectCoverage: CI,
collectCoverageFrom: ['src', '!src/test']
};
32 changes: 17 additions & 15 deletions package.json
Expand Up @@ -2,28 +2,28 @@
"name": "graphql-tools",
"version": "5.0.0-alpha.0",
"description": "Useful tools to create and manipulate GraphQL schemas.",
"main": "dist/index.js",
"sideEffects": false,
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
},
"files": [
"/dist",
"!/dist/test"
],
"sideEffects": false,
"scripts": {
"clean": "rimraf dist",
"build": "npm run compile",
"precompile": "npm run clean",
"compile": "tsc",
"pretest": "npm run clean && npm run compile",
"test": "npm run testonly",
"compile": "rollup -c rollup.config.js",
"test": "jest",
"posttest": "npm run lint && npm run prettier:check",
"lint": "eslint --ext .js,.ts src",
"lint:watch": "esw --watch --cache --ext .js,.ts src",
"watch": "tsc -w",
"testonly": "mocha --reporter spec --full-trace ./dist/test/**.js --require source-map-support/register",
"testonly:cover": "nyc npm run testonly",
"testonly:watch": "mocha -w --reporter spec --full-trace ./dist/test/**.js --require source-map-support/register",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"watch": "npm run compile -- --watch",
"prepublishOnly": "npm run compile",
"prettier": "prettier --trailing-comma all --single-quote --write src/**/*.ts",
"prettier:check": "prettier --trailing-comma all --single-quote --check src/**/*.ts"
Expand Down Expand Up @@ -63,21 +63,20 @@
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0-rc"
},
"devDependencies": {
"@types/chai": "4.2.11",
"@rollup/plugin-node-resolve": "7.1.1",
"@types/dateformat": "3.0.1",
"@types/express": "4.17.3",
"@types/extract-files": "3.1.0",
"@types/graphql-type-json": "0.3.2",
"@types/graphql-upload": "8.0.3",
"@types/mocha": "7.0.2",
"@types/jest": "25.1.4",
"@types/node": "13.9.3",
"@types/node-fetch": "2.5.5",
"@types/uuid": "7.0.2",
"@typescript-eslint/eslint-plugin": "2.25.0",
"@typescript-eslint/parser": "2.25.0",
"babel-eslint": "10.1.0",
"body-parser": "1.19.0",
"chai": "4.2.0",
"coveralls": "3.0.11",
"dataloader": "2.0.0",
"dateformat": "3.0.3",
Expand All @@ -90,11 +89,14 @@
"graphql-subscriptions": "1.1.0",
"graphql-type-json": "0.3.1",
"graphql-upload": "10.0.0",
"mocha": "7.1.1",
"nyc": "15.0.0",
"jest": "25.2.4",
"prettier": "2.0.2",
"rimraf": "3.0.2",
"rollup": "2.3.1",
"rollup-plugin-auto-external": "2.0.0",
"rollup-plugin-typescript2": "0.27.0",
"source-map-support": "0.5.16",
"ts-jest": "25.3.0",
"typescript": "3.8.3",
"zen-observable-ts": "0.8.20"
}
Expand Down
30 changes: 30 additions & 0 deletions rollup.config.js
@@ -0,0 +1,30 @@
import rollup from 'rollup';
import autoExternal from 'rollup-plugin-auto-external';
import resolveNode from '@rollup/plugin-node-resolve';
import rollupTypescript from 'rollup-plugin-typescript2';

const commonOutputOptions = {
preferConst: true,
sourcemap: true
};

export default {
input: 'src/index.ts',
plugins: [
resolveNode(),
autoExternal({ builtins: true, dependencies: true, peerDependencies: true }),
rollupTypescript()
],
output: [
{
...commonOutputOptions,
file: 'dist/index.cjs.js',
format: 'cjs'
},
{
...commonOutputOptions,
file: 'dist/index.esm.js',
format: 'esm'
}
]
};

0 comments on commit b7d6a88

Please sign in to comment.