Skip to content

Commit 1dfd616

Browse files
authored
Use Jest to test date-fns in Node.js (date-fns#1192) (closes date-fns#875; closes date-fns#1066)
* Setup Jest * Update Babel and Power Assert * Make test karma suite work * Fix multiple it used instead of describe * Fix accidentally disabled tests * Upgrade Sinon * Add Node.js suite to Travis CI * Remove node_modules from .flowconfig ignore * Remove console.log from a test * Use regexp for exception assertion to make it work in any Node.js * Disable Sauce Connect because it gives me headaches
1 parent 8b8952a commit 1dfd616

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+6542
-4372
lines changed

.babelrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2-
"presets": ["es2015", "babel-preset-power-assert"],
2+
"presets": [
3+
["@babel/preset-env", { "modules": "commonjs" }],
4+
"babel-preset-power-assert"
5+
],
36
"plugins": ["add-module-exports"]
47
}

.flowconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[ignore]
2-
.*node_modules*
32
.*examples*
43
[options]
54
suppress_comment= \\(.\\|\n\\)*\\$ExpectedMistake

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 10.15.3

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
- TEST_SUITE=main
1313
- TEST_SUITE=tz TZ_LENGTH=2 TZ_INDEX=0
1414
- TEST_SUITE=tz TZ_LENGTH=2 TZ_INDEX=1
15+
- TEST_SUITE=node
1516

1617
before_install:
1718
- export CHROME_BIN=chromium-browser
@@ -39,4 +40,4 @@ cache: yarn
3940

4041
addons:
4142
chrome: stable
42-
sauce_connect: true
43+
# sauce_connect: true

config/karma.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ function config(config) {
148148
'karma-mocha-reporter',
149149
'karma-phantomjs-launcher',
150150
'karma-chrome-launcher',
151-
'karma-sauce-launcher',
152-
'karma-sinon',
151+
// TODO: Make it work
152+
// 'karma-sauce-launcher',
153153
'karma-sourcemap-loader',
154154
'karma-webpack',
155155
'karma-benchmark',
@@ -172,7 +172,7 @@ function getFrameworksConfig() {
172172
if (process.env.TEST_BENCHMARK) {
173173
return ['benchmark']
174174
} else {
175-
return ['mocha', 'sinon']
175+
return ['mocha']
176176
}
177177
}
178178

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
verbose: false,
3+
setupFiles: ['jest-plugin-context/setup'],
4+
testPathIgnorePatterns: ['<rootDir>/test.js']
5+
}

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
},
4040
"dependencies": {},
4141
"devDependencies": {
42-
"babel": "^6.5.2",
43-
"babel-cli": "^6.6.5",
44-
"babel-eslint": "^8.2.1",
45-
"babel-loader": "7.1.5",
46-
"babel-plugin-add-module-exports": "^0.2.1",
47-
"babel-preset-es2015": "^6.6.0",
48-
"babel-preset-power-assert": "^1.0.0",
42+
"@babel/cli": "^7.4.4",
43+
"@babel/core": "^7.4.5",
44+
"@babel/node": "^7.4.5",
45+
"@babel/preset-env": "^7.4.5",
46+
"babel-loader": "8.0.6",
47+
"babel-plugin-add-module-exports": "^1.0.2",
48+
"babel-preset-power-assert": "^3.0.0",
4949
"cloc": "^2.2.0",
5050
"coveralls": "^3.0.2",
5151
"firebase": "^3.7.1",
@@ -55,6 +55,8 @@
5555
"gzip-size-cli": "^1.0.0",
5656
"husky": "^1.0.0-rc.7",
5757
"istanbul-instrumenter-loader": "^3.0.1",
58+
"jest": "^24.8.0",
59+
"jest-plugin-context": "^2.9.0",
5860
"js-beautify": "^1.5.10",
5961
"jsdoc-to-markdown": "leshakoss/jsdoc-to-markdown",
6062
"karma": "^3.0.0",
@@ -68,7 +70,6 @@
6870
"karma-mocha-reporter": "^2.2.5",
6971
"karma-phantomjs-launcher": "^1.0.4",
7072
"karma-sauce-launcher": "^1.2.0",
71-
"karma-sinon": "^1.0.4",
7273
"karma-sourcemap-loader": "^0.3.5",
7374
"karma-webpack": "^4.0.0-rc.5",
7475
"lint-staged": "^7.1.1",
@@ -80,7 +81,7 @@
8081
"node-fetch": "^1.3.3",
8182
"power-assert": "^1.3.1",
8283
"prettier": "^1.14.3",
83-
"sinon": "^1.17.3",
84+
"sinon": "^7.3.2",
8485
"size-limit": "^0.21.0",
8586
"snazzy": "^7.0.0",
8687
"systemjs": "^0.19.39",

scripts/test/node.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
# The script runs the test suite using Jest in different Node.js versions.
4+
#
5+
# It's a part of the test process.
6+
7+
set -ex
8+
9+
export PATH="$(yarn bin):$PATH"
10+
11+
# Update and source nvm
12+
curl -o ~/.nvm/nvm.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/nvm.sh
13+
source ~/.nvm/nvm.sh
14+
15+
for version in 8 9 10 11 12
16+
do
17+
echo "Running tests using Node.js $version"
18+
nvm install $version
19+
npm rebuild
20+
jest
21+
done

scripts/test/travis.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ then
3636
yarn test-cross-browser
3737
env TEST_CROSS_BROWSER=true yarn test --single-run
3838

39+
elif [ "$TEST_SUITE" == "node" ]
40+
then
41+
./scripts/test/node.sh
42+
3943
else
4044
printf "\n\033[0;31m" "UNKNOWN SUITE!" "\033[0m\n"
4145
exit 1

src/_lib/protectedTokens/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export function isProtectedWeekYearToken(token) {
1212
export function throwProtectedError(token) {
1313
if (token === 'YYYY') {
1414
throw new RangeError(
15-
'Use `yyyy` instead of `YYYY` for formating years; see: https://git.io/fxCyr'
15+
'Use `yyyy` instead of `YYYY` for formatting years; see: https://git.io/fxCyr'
1616
)
1717
} else if (token === 'YY') {
1818
throw new RangeError(
19-
'Use `yy` instead of `YY` for formating years; see: https://git.io/fxCyr'
19+
'Use `yy` instead of `YY` for formatting years; see: https://git.io/fxCyr'
2020
)
2121
} else if (token === 'D') {
2222
throw new RangeError(

0 commit comments

Comments
 (0)