Skip to content

Commit 0d9a2b7

Browse files
committed
Add tests to ensure builds works correctly in node env
1 parent 7ffa437 commit 0d9a2b7

File tree

3 files changed

+57
-19
lines changed

3 files changed

+57
-19
lines changed

jest.config.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
const ignoreFiles = ['<rootDir>/playgrounds', '<rootDir>/tests/assets']
2+
13
module.exports = {
24
verbose: true,
35
watchPlugins: [
46
'jest-watch-typeahead/filename',
57
'jest-watch-typeahead/testname',
68
],
79
projects: [
10+
{
11+
displayName: 'build',
12+
testEnvironment: 'node',
13+
testPathIgnorePatterns: [...ignoreFiles, '<rootDir>/tests/*.ts'],
14+
testMatch: ['**/*.tests.js', '/tests/**/*.js'],
15+
},
816
{
917
globals: {
1018
'ts-jest': {
@@ -13,14 +21,7 @@ module.exports = {
1321
},
1422
preset: 'ts-jest',
1523
displayName: 'dom',
16-
// We are using jest-environment-jsdom 25 until we stop supporting node 10
17-
// jest-environment-jsdom 25 uses jsdom 15 which still supports node 10
18-
testEnvironment: 'jest-environment-jsdom',
19-
testPathIgnorePatterns: [
20-
'<rootDir>/tests/env',
21-
'<rootDir>/playgrounds',
22-
'<rootDir>/tests/assets',
23-
],
24+
testPathIgnorePatterns: [...ignoreFiles, '<rootDir>/tests/build*'],
2425
testMatch: ['**/*.tests.ts', '/tests/**/*.ts'],
2526
},
2627
{
@@ -32,11 +33,7 @@ module.exports = {
3233
preset: 'ts-jest',
3334
displayName: 'node',
3435
testEnvironment: 'node',
35-
testPathIgnorePatterns: [
36-
'<rootDir>/tests/env',
37-
'<rootDir>/playgrounds',
38-
'<rootDir>/tests/assets',
39-
],
36+
testPathIgnorePatterns: [...ignoreFiles],
4037
testMatch: ['**/*.tests.ts', '/tests/**/*.ts'],
4138
},
4239
],

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"scripts": {
77
"cleanup": "shx rm -rf dist/",
88
"test:watch": "yarn test --watch",
9-
"test": "jest --runInBand",
10-
"test:e2e": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:javascript\" \"cypress run --env playground=javascript\"",
9+
"test": "jest --runInBand --selectProjects dom --selectProjects node",
10+
"test:build": "yarn build && jest --runInBand --selectProjects build",
11+
"test:e2e": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:angular\" \"cypress run --env playground=angular\"",
1112
"test:e2e:all": "sh scripts/e2e.sh",
12-
"test:e2e:watch": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:javascript\" \"cypress open --env playground=javascript\"",
13-
"test:all": "yarn test:e2e:all && yarn test",
13+
"test:e2e:watch": "concurrently --kill-others -s first \"NODE_ENV=test yarn playground:angular\" \"cypress open --env playground=angular\"",
14+
"test:all": "yarn test:e2e:all && yarn test && test:build",
1415
"playground:vue": "yarn --cwd ./playgrounds/vue && yarn --cwd ./playgrounds/vue serve",
1516
"playground:react": "yarn --cwd ./playgrounds/react && yarn --cwd ./playgrounds/react start",
1617
"playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript start",
@@ -59,7 +60,6 @@
5960
"@babel/preset-env": "^7.15.0",
6061
"@rollup/plugin-commonjs": "^17.1.0",
6162
"@rollup/plugin-node-resolve": "^11.2.0",
62-
"@rollup/plugin-typescript": "^8.2.5",
6363
"@typescript-eslint/eslint-plugin": "^4.16.1",
6464
"@typescript-eslint/parser": "^4.16.1",
6565
"@vue/eslint-config-typescript": "^7.0.0",
@@ -86,13 +86,14 @@
8686
"eslint-plugin-vue": "^7.7.0",
8787
"instantsearch.js": "^4.16.1",
8888
"jest": "^26.6.3",
89-
"jest-environment-jsdom": "25.5",
9089
"jest-watch-typeahead": "^0.6.3",
9190
"prettier": "^2.0.0",
9291
"regenerator-runtime": "^0.13.7",
9392
"rollup": "^2.40.0",
9493
"rollup-plugin-babel": "^4.4.0",
94+
"rollup-plugin-node-polyfills": "^0.2.1",
9595
"rollup-plugin-terser": "^7.0.0",
96+
"rollup-plugin-typescript2": "^0.30.0",
9697
"shx": "^0.3.3",
9798
"ts-jest": "^26.5.2",
9899
"tslib": "^2.3.1",

tests/build.tests.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const {
2+
instantMeiliSearch: UMDinstantMeiliSearch,
3+
} = require('../dist/instant-meilisearch.umd')
4+
const {
5+
instantMeiliSearch: CJSinstantMeiliSearch,
6+
} = require('../dist/instant-meilisearch.cjs')
7+
8+
const UMDclient = UMDinstantMeiliSearch('http://localhost:7700', 'masterKey')
9+
const CJSclient = CJSinstantMeiliSearch('http://localhost:7700', 'masterKey')
10+
const instantsearch = require('instantsearch.js')
11+
12+
test('UMD client should correctly created', () => {
13+
expect(UMDclient.MeiliSearchClient.config.apiKey).toBe('masterKey')
14+
})
15+
16+
test('CJS client should correctly created', () => {
17+
expect(CJSclient.MeiliSearchClient.config.apiKey).toBe('masterKey')
18+
})
19+
20+
test('CJS instantsearch client should correctly created', () => {
21+
const CJSInstantSearch = instantsearch.default({
22+
indexName: 'cjs_index',
23+
searchClient: CJSclient,
24+
})
25+
expect(CJSInstantSearch.indexName).toBe('cjs_index')
26+
expect(CJSInstantSearch.client.MeiliSearchClient.config.apiKey).toBe(
27+
'masterKey'
28+
)
29+
})
30+
31+
test('UMD instantsearch client should correctly created', () => {
32+
const UMDInstantSearch = instantsearch.default({
33+
indexName: 'umd_index',
34+
searchClient: UMDclient,
35+
})
36+
expect(UMDInstantSearch.indexName).toBe('umd_index')
37+
expect(UMDInstantSearch.client.MeiliSearchClient.config.apiKey).toBe(
38+
'masterKey'
39+
)
40+
})

0 commit comments

Comments
 (0)