Skip to content

Commit

Permalink
Merge pull request #12 from entria/feat/jestBabelTransformer
Browse files Browse the repository at this point in the history
feat(jest): use custom babel transformer to make work on monorepo
  • Loading branch information
italosestilon authored Nov 14, 2018
2 parents 4c01f36 + af38f0b commit 3062451
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 42 deletions.
21 changes: 20 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
const { workspaces = [] } = require('./package.json');

module.exports = {
babelrcRoots: workspaces.packages || workspaces
presets: [
'@babel/preset-flow',
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-transform-async-to-generator',
'@babel/plugin-syntax-async-generators',
],
};
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
'<rootDir>/packages/server/jest.config.js'
],
transform: {
'^.+\\.(js|ts|tsx)?$': 'babel-jest',
// '^.+\\.(js|ts|tsx)?$': 'babel-jest',
'^.+\\.(js|ts|tsx)?$': '<rootDir>/test/babel-transformer',
},
moduleFileExtensions: ['ts', 'js', 'tsx'],
moduleFileExtensions: ['js', 'css', 'ts', 'tsx'],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/node": "7.0.0",
"babel-core": "^7.0.0-bridge.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-do-expressions": "^7.0.0",
Expand Down
17 changes: 1 addition & 16 deletions packages/server/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
},
},
],
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
Expand All @@ -18,20 +19,4 @@ module.exports = {
'@babel/plugin-transform-async-to-generator',
'@babel/plugin-syntax-async-generators',
],
overrides: [
{
test: ['./src/**/*.ts'],
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
},
],
};
24 changes: 24 additions & 0 deletions packages/server/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { workspaces = [] } = require('./package.json');

module.exports = {
presets: [
'@babel/preset-flow',
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-transform-async-to-generator',
'@babel/plugin-syntax-async-generators',
],
};
43 changes: 23 additions & 20 deletions packages/server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@ const pack = require("./package");
module.exports = {
displayName: pack.name,
name: pack.name,
testEnvironment: '<rootDir>/packages/server/test/environment/mongodb',
testEnvironment: '<rootDir>/test/environment/mongodb',
// testPathIgnorePatterns: ignoredPaths,
// coverageReporters: ['lcov', 'html'],
setupTestFrameworkScriptFile: '<rootDir>/packages/server/test/setupTestFramework.js',
globalSetup: '<rootDir>/packages/server/test/setup.js',
globalTeardown: '<rootDir>/packages/server/test/teardown.js',
setupTestFrameworkScriptFile: '<rootDir>/test/setupTestFramework.js',
globalSetup: '<rootDir>/test/setup.js',
globalTeardown: '<rootDir>/test/teardown.js',
resetModules: false,
// reporters: [
// 'default',
// [
// 'jest-junit',
// {
// suiteName: 'GraphQL Dataloader Boilerplate Tests',
// output: './test-results/jest/results.xml',
// },
// ],
// ],
// transform: {
// '^.+\\.(js|ts|tsx)?$': 'babel-jest',
// },
moduleFileExtensions: ['ts', 'js', 'tsx'],
// testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js?|ts?)$',
// rootDir: "../..",
reporters: [
'default',
[
'jest-junit',
{
suiteName: 'GraphQL Dataloader Boilerplate Tests',
output: './test-results/jest/results.xml',
},
],
],
transform: {
// '^.+\\.(js|ts|tsx)?$': 'babel-jest',
// '^.+\\.(js|ts|tsx)?$': '<rootDir>/node_modules/babel-jest',
// '^.+\\.(js|ts|tsx)?$': '<rootDir>/../../node_modules/babel-jest',
'^.+\\.(js|ts|tsx)?$': '<rootDir>/test/babel-transformer',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js?|ts?)$',
moduleFileExtensions: ['ts', 'js'],

};
8 changes: 6 additions & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"version": "0.0.1",
"private": true,
"dependencies": {
"@babel/core": "^7.1.6",
"@babel/polyfill": "^7.0.0",
"@entria/graphql-mongoose-loader": "^2.1.1",
"apollo-server-koa": "^2.0.4",
"babel-core": "^7.0.0-bridge.0",
"bcryptjs": "^2.4.3",
"dataloader": "^1.4.0",
"dotenv-safe": "^4.0.4",
Expand All @@ -33,7 +35,7 @@
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/core": "^7.1.6",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
Expand Down Expand Up @@ -72,6 +74,8 @@
"esm": "^3.0.5",
"flow-bin": "^0.80.0",
"husky": "^0.14.3",
"jest-fetch-mock": "^1.7.4",
"jest-junit": "^5.2.0",
"jest-runner-eslint": "^0.6.0",
"lint-staged": "7.2.2",
"mongodb-memory-server": "^2.1.0",
Expand All @@ -98,7 +102,7 @@
"repl": "nodemon --config ./repl/nodemon.json ./repl.js --exec babel-node",
"serve": "node dist/index.js",
"start": "nodemon --extensions \".es6,.js,.es,.jsx,.mjs,.ts\" src/index.js",
"test": "jest --coverage",
"test": "jest",
"test:watch": "jest --watch --coverage",
"update-schema": "babel-node --extensions \".es6,.js,.es,.jsx,.mjs,.ts\" ./scripts/updateSchema.js"
}
Expand Down
7 changes: 7 additions & 0 deletions packages/server/test/babel-transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const config = require('../babel.config');

const { createTransformer } = require('babel-jest');

module.exports = createTransformer({
...config,
});
12 changes: 12 additions & 0 deletions test/babel-transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const config = require('../babel.config');
const { join, resolve } = require('path');

const { createTransformer } = require('babel-jest');

const packagePath = resolve('../');
const packageGlob = join(packagePath, '*');

module.exports = createTransformer({
// babelrcRoots: packageGlob,
...config,
});
99 changes: 98 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@
semver "^5.4.1"
source-map "^0.5.0"

"@babel/core@^7.1.6":
version "7.1.6"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.1.6.tgz#3733cbee4317429bc87c62b29cf8587dba7baeb3"
integrity sha512-Hz6PJT6e44iUNpAn8AoyAs6B3bl60g7MJQaI0rZEar6ECzh6+srYO1xlIdssio34mPaUtAb1y+XlkkSJzok3yw==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.1.6"
"@babel/helpers" "^7.1.5"
"@babel/parser" "^7.1.6"
"@babel/template" "^7.1.2"
"@babel/traverse" "^7.1.6"
"@babel/types" "^7.1.6"
convert-source-map "^1.1.0"
debug "^4.1.0"
json5 "^2.1.0"
lodash "^4.17.10"
resolve "^1.3.2"
semver "^5.4.1"
source-map "^0.5.0"

"@babel/generator@7.0.0-beta.54":
version "7.0.0-beta.54"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0-beta.54.tgz#c043c7eebeebfd7e665d95c281a4aafc83d4e1c9"
Expand All @@ -82,6 +102,17 @@
source-map "^0.5.0"
trim-right "^1.0.1"

"@babel/generator@^7.1.6":
version "7.1.6"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.1.6.tgz#001303cf87a5b9d093494a4bf251d7b5d03d3999"
integrity sha512-brwPBtVvdYdGxtenbQgfCdDPmtkmUBZPjUoK5SXJEBuHaA5BCubh9ly65fzXz7R6o5rA76Rs22ES8Z+HCc0YIQ==
dependencies:
"@babel/types" "^7.1.6"
jsesc "^2.5.1"
lodash "^4.17.10"
source-map "^0.5.0"
trim-right "^1.0.1"

"@babel/helper-annotate-as-pure@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz#323d39dd0b50e10c7c06ca7d7638e6864d8c5c32"
Expand Down Expand Up @@ -286,6 +317,11 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.1.5.tgz#20b7d5e7e1811ba996f8a868962ea7dd2bfcd2fc"
integrity sha512-WXKf5K5HT6X0kKiCOezJZFljsfxKV1FpU8Tf1A7ZpGvyd/Q4hlrJm2EwoH2onaUq3O4tLDp+4gk0hHPsMyxmOg==

"@babel/parser@^7.1.6":
version "7.1.6"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.1.6.tgz#16e97aca1ec1062324a01c5a6a7d0df8dd189854"
integrity sha512-dWP6LJm9nKT6ALaa+bnL247GHHMWir3vSlZ2+IHgHgktZQx0L3Uvq2uAWcuzIe+fujRsYWBW2q622C5UvGK9iQ==

"@babel/plugin-external-helpers@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-external-helpers/-/plugin-external-helpers-7.0.0.tgz#61ee7ba5dba27d7cad72a13d46bec23c060b762e"
Expand Down Expand Up @@ -1009,6 +1045,21 @@
globals "^11.1.0"
lodash "^4.17.10"

"@babel/traverse@^7.1.6":
version "7.1.6"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.1.6.tgz#c8db9963ab4ce5b894222435482bd8ea854b7b5c"
integrity sha512-CXedit6GpISz3sC2k2FsGCUpOhUqKdyL0lqNrImQojagnUMXf8hex4AxYFRuMkNGcvJX5QAFGzB5WJQmSv8SiQ==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.1.6"
"@babel/helper-function-name" "^7.1.0"
"@babel/helper-split-export-declaration" "^7.0.0"
"@babel/parser" "^7.1.6"
"@babel/types" "^7.1.6"
debug "^4.1.0"
globals "^11.1.0"
lodash "^4.17.10"

"@babel/types@7.0.0-beta.54":
version "7.0.0-beta.54"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.54.tgz#025ad68492fed542c13f14c579a44c848e531063"
Expand All @@ -1027,6 +1078,15 @@
lodash "^4.17.10"
to-fast-properties "^2.0.0"

"@babel/types@^7.1.6":
version "7.1.6"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.1.6.tgz#0adb330c3a281348a190263aceb540e10f04bcce"
integrity sha512-DMiUzlY9DSjVsOylJssxLHSgj6tWM9PRFJOGW/RaOglVOK9nzTxoOMfTfRQXGUCUQ/HmlG2efwC+XqUEJ5ay4w==
dependencies:
esutils "^2.0.2"
lodash "^4.17.10"
to-fast-properties "^2.0.0"

"@commitlint/cli@6.0.5":
version "6.0.5"
resolved "https://registry.yarnpkg.com/@commitlint/cli/-/cli-6.0.5.tgz#c159c41434d24167c2f52c29e81cffc1959a6d0f"
Expand Down Expand Up @@ -4477,6 +4537,14 @@ cross-fetch@2.2.2:
node-fetch "2.1.2"
whatwg-fetch "2.0.4"

cross-fetch@^2.2.2:
version "2.2.3"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.2.3.tgz#e8a0b3c54598136e037f8650f8e823ccdfac198e"
integrity sha512-PrWWNH3yL2NYIb/7WF/5vFG3DCQiXDOVf8k3ijatbrtnwNuhMWLC7YF7uqf53tbTFDzHIUD8oITw4Bxt8ST3Nw==
dependencies:
node-fetch "2.1.2"
whatwg-fetch "2.0.4"

cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -7870,6 +7938,14 @@ jest-environment-node@^23.4.0:
jest-mock "^23.2.0"
jest-util "^23.4.0"

jest-fetch-mock@^1.7.4:
version "1.7.4"
resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-1.7.4.tgz#2d1f89dfeba644c7d8f97e43ee7931e147838809"
integrity sha512-uwwwT0tVQGWytJzg/Nw6sFUMuTx7H9bmkp37Su39LjnPb1zd+AAXmYWEhuXESs6S74g98yZafDqyo6wBkObb2g==
dependencies:
cross-fetch "^2.2.2"
promise-polyfill "^7.1.1"

jest-get-type@^22.1.0:
version "22.4.3"
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4"
Expand Down Expand Up @@ -7921,6 +7997,17 @@ jest-jasmine2@^23.6.0:
jest-util "^23.4.0"
pretty-format "^23.6.0"

jest-junit@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-5.2.0.tgz#980401db7aa69999cf117c6d740a8135c22ae379"
integrity sha512-Mdg0Qpdh1Xm/FA1B/mcLlmEmlr3XzH5pZg7MvcAwZhjHijPRd1z/UwYwkwNHmCV7o4ZOWCf77nLu7ZkhHHrtJg==
dependencies:
jest-config "^23.6.0"
jest-validate "^23.0.1"
mkdirp "^0.5.1"
strip-ansi "^4.0.0"
xml "^1.0.1"

jest-leak-detector@^23.6.0:
version "23.6.0"
resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-23.6.0.tgz#e4230fd42cf381a1a1971237ad56897de7e171de"
Expand Down Expand Up @@ -8076,7 +8163,7 @@ jest-util@^23.4.0:
slash "^1.0.0"
source-map "^0.6.0"

jest-validate@^23.5.0, jest-validate@^23.6.0:
jest-validate@^23.0.1, jest-validate@^23.5.0, jest-validate@^23.6.0:
version "23.6.0"
resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-23.6.0.tgz#36761f99d1ed33fcd425b4e4c5595d62b6597474"
integrity sha512-OFKapYxe72yz7agrDAWi8v2WL8GIfVqcbKRCLbRG9PAxtzF9b1SEDdTpytNDN12z2fJynoBwpMpvj2R39plI2A==
Expand Down Expand Up @@ -10893,6 +10980,11 @@ promise-inflight@^1.0.1:
resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3"
integrity sha1-mEcocL8igTL8vdhoEputEsPAKeM=

promise-polyfill@^7.1.1:
version "7.1.2"
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-7.1.2.tgz#ab05301d8c28536301622d69227632269a70ca3b"
integrity sha512-FuEc12/eKqqoRYIGBrUptCBRhobL19PS2U31vMNTfyck1FxPyMfgsXyW4Mav85y/ZN1hop3hOwRlUDok23oYfQ==

promise-retry@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/promise-retry/-/promise-retry-1.1.1.tgz#6739e968e3051da20ce6497fb2b50f6911df3d6d"
Expand Down Expand Up @@ -13674,6 +13766,11 @@ xml-name-validator@^3.0.0:
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==

xml@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=

xmlbuilder@8.2.2:
version "8.2.2"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-8.2.2.tgz#69248673410b4ba42e1a6136551d2922335aa773"
Expand Down

0 comments on commit 3062451

Please sign in to comment.