Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit cfd250f

Browse files
Merge pull request #321 from gastrohero/feature/add-jest-support
Feature/add jest support
2 parents 7d395e6 + f19fcf3 commit cfd250f

File tree

7 files changed

+1754
-34
lines changed

7 files changed

+1754
-34
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ jobs:
2121
- <<: *build
2222
node_js: '8'
2323

24+
- &unit
25+
stage: Test
26+
script: yarn test:unit
27+
name: "NodeJS 10 unit tests"
28+
node_js: "10"
29+
30+
- <<: *unit
31+
name: "NodeJS 8 unit tests"
32+
node_js: "8"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Constant for Mailchimp subscription status - @KonstantinSoelch (#294)
1111
- mage2vs import now has optional `--generate-unique-url-keys` parameter which defaults to `false` to enable/disable the url key generation with name and id for categories - @rain2o (#232)
1212
- Added eslint config from vue-storefront so we have the same config and in both repos typescript support - @resubaka (#320)
13+
- Added jest support - @resubaka (#321)
1314

1415
### Fixed
1516
- The `product.price_*` fields have been normalized with the backward compatibility support (see `config.tax.deprecatedPriceFieldsSupport` which is by default true) - @pkarw (#289)

config/test.json

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

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"migrate": "node node_modules/migrate/bin/migrate",
3232
"prestart": "npm run -s build",
3333
"test": "eslint src",
34+
"test:unit": "jest -c test/unit/jest.conf.js",
3435
"setup": "npm run restore; npm run migrate",
3536
"lint": "eslint --ext .js,.ts src migrations scripts --fix"
3637
},
@@ -88,11 +89,13 @@
8889
"@types/body-parser": "^1.17.0",
8990
"@types/config": "^0.0.34",
9091
"@types/express": "^4.16.1",
92+
"@types/jest": "^24.0.11",
9193
"@types/node": "^11.13.4",
9294
"@typescript-eslint/eslint-plugin": "^1.7.1-alpha.17",
9395
"@typescript-eslint/parser": "^1.7.1-alpha.17",
9496
"apollo-server-express": "^1.3.6",
9597
"cpx": "^1.5.0",
98+
"jest": "^24.8.0",
9699
"eslint": "^5.0.0",
97100
"eslint-config-standard": "^11.0.0",
98101
"eslint-plugin-import": "^2.13.0",
@@ -101,6 +104,7 @@
101104
"eslint-plugin-standard": "^3.1.0",
102105
"eslint-plugin-vue-storefront": "^0.0.1",
103106
"nodemon": "^1.18.7",
107+
"ts-jest": "^24.0.2",
104108
"pre-commit": "^1.2.2",
105109
"ts-node": "^8.1.0",
106110
"tslib": "^1.9.3",

src/lib/test/unit/boost.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import getBoosts from '../../boost'
2+
3+
describe('getBoosts method', () => {
4+
describe('with empty boost config', () => {
5+
beforeEach(() => {
6+
jest.mock('config', () => ({}))
7+
})
8+
9+
it('Should return 1', () => {
10+
const result = getBoosts('color');
11+
expect(result).toEqual(1);
12+
});
13+
})
14+
15+
describe('with boost config', () => {
16+
beforeEach(() => {
17+
jest.mock('config', () => ({
18+
boost: {
19+
name: 3
20+
}
21+
}))
22+
})
23+
24+
it('color not in config and should be 1', () => {
25+
const result = getBoosts('color');
26+
expect(result).toEqual(1);
27+
});
28+
29+
it('name is in config and should be 3', () => {
30+
const result = getBoosts('name');
31+
expect(result).toEqual(3);
32+
});
33+
})
34+
})

test/unit/jest.conf.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
rootDir: '../../',
3+
moduleFileExtensions: [
4+
'js',
5+
'ts',
6+
'json'
7+
],
8+
testMatch: [
9+
'<rootDir>/src/**/test/unit/**/*.spec.(js|ts)',
10+
],
11+
transform: {
12+
'^.+\\.js$': '<rootDir>/node_modules/ts-jest',
13+
'^.+\\.ts$': '<rootDir>/node_modules/ts-jest',
14+
},
15+
coverageDirectory: '<rootDir>/test/unit/coverage',
16+
collectCoverageFrom: [
17+
'src/**/*.{js,ts}',
18+
'!src/**/types/*.{js,ts}',
19+
],
20+
moduleNameMapper: {
21+
'^src(.*)$': '<rootDir>/src$1'
22+
},
23+
transformIgnorePatterns: [
24+
'<rootDir>/node_modules/(?!lodash)'
25+
]
26+
}

0 commit comments

Comments
 (0)