Skip to content

Commit

Permalink
fix(jest): make jest be able to transform yaml files
Browse files Browse the repository at this point in the history
fixes #253
  • Loading branch information
evansiroky committed Oct 11, 2018
1 parent 3cd4b7d commit a240c03
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 deletions.
6 changes: 6 additions & 0 deletions __tests__/lib/__snapshots__/jest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Array [
"another-folder",
],
"coverageDirectory": "coverage",
"moduleFileExtensions": Array [
"js",
"jsx",
"json",
"yml",
],
"notify": true,
"setupFiles": Array [
"beforeTestsSetup.js",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('jest.js', () => {
updateSnapshots: true
})
cfg[JEST_CONFIG_INDEX] = JSON.parse(cfg[JEST_CONFIG_INDEX])
expect(cfg[JEST_CONFIG_INDEX].transform['.*']).toContain(
expect(cfg[JEST_CONFIG_INDEX].transform['^.+\\.jsx?$']).toContain(
'lib/jest-preprocessor.js'
)
delete cfg[JEST_CONFIG_INDEX].transform
Expand Down
7 changes: 3 additions & 4 deletions __tests__/test-utils/mocks/index-with-yaml.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, {Component} from 'react'
import uuid from 'uuid'

const yaml = require('./mock.yaml')
console.log(yaml)
const yaml = require('./mock.yml')

/**
* A Mock Component to test to ensure that building of React jsx components works
Expand All @@ -16,8 +15,8 @@ export default class MockTestComponentUniqueName extends Component {
* Render the component.
*/
render () {
console.log(yaml)
console.log(uuid.v4())
return <div />
}
}

console.log(uuid.v4())
File renamed without changes.
11 changes: 10 additions & 1 deletion lib/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ module.exports.generateTestConfig = (patterns, options) => {
collectCoverage: options.coverage,
collectCoverageFrom: ['lib/**/*.js'],
coverageDirectory: 'coverage',
moduleFileExtensions: [
'js',
'jsx',
'json',
'yml'
],
notify: true,
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/__tests__/test-utils'
],
testURL: 'http://localhost:9966',
transform: { '.*': path.resolve(__dirname, 'jest-preprocessor.js') }
transform: {
'\\.yml$': 'jest-yaml-transform',
'^.+\\.jsx?$': path.resolve(__dirname, 'jest-preprocessor.js')
}
}

if (options.coveragePaths) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"glob": "^7.1.3",
"isomorphic-fetch": "^2.2.1",
"jest": "^23.5.0",
"jest-yaml-transform": "^0.2.0",
"lodash.uniq": "^4.5.0",
"middleware-proxy": "^2.0.2",
"mime": "^2.3.1",
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4095,6 +4095,13 @@ flat-cache@^1.2.1:
graceful-fs "^4.1.2"
write "^0.2.1"

flat@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/flat/-/flat-4.1.0.tgz#090bec8b05e39cba309747f1d588f04dbaf98db2"
integrity sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw==
dependencies:
is-buffer "~2.0.3"

flatten@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
Expand Down Expand Up @@ -5099,6 +5106,11 @@ is-buffer@^1.1.0, is-buffer@^1.1.5, is-buffer@~1.1.1:
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==

is-buffer@~2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725"
integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==

is-builtin-module@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe"
Expand Down Expand Up @@ -5859,6 +5871,14 @@ jest-worker@^23.2.0:
dependencies:
merge-stream "^1.0.1"

jest-yaml-transform@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/jest-yaml-transform/-/jest-yaml-transform-0.2.0.tgz#7e14ed59e563283b73be7e8f387f352e669147a4"
integrity sha512-Pu1KyURgi0Qfi0QrUr2xwV7SlYRxasLS+bPZfLxFks93LCIYFHdGnQ7pNxvqOrZdyBNXthCUT98JBjo4UCWflQ==
dependencies:
flat "^4.0.0"
js-yaml "^3.9.1"

jest@^23.5.0:
version "23.5.0"
resolved "https://registry.yarnpkg.com/jest/-/jest-23.5.0.tgz#80de353d156ea5ea4a7332f7962ac79135fbc62e"
Expand Down

0 comments on commit a240c03

Please sign in to comment.