Skip to content

Commit 0dea758

Browse files
committed
Add Jest testing
1 parent dabc459 commit 0dea758

8 files changed

+2512
-99
lines changed

.ci/azure-pipelines.yml

+62-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ trigger:
77
tags:
88
include:
99
- '*'
10+
pr:
11+
branches:
12+
include:
13+
- '*'
1014

1115
jobs:
1216
- job: main_build
@@ -24,8 +28,16 @@ jobs:
2428
inputs:
2529
versionSpec: '10.x'
2630

27-
- script: 'yarn install'
31+
- task: Cache@2
32+
displayName: 'Check Cache'
33+
inputs:
34+
key: 'yarn | yarn.lock'
35+
path: 'node_modules'
36+
cacheHitVar: CACHE_RESTORED
37+
38+
- script: 'yarn install --frozen-lockfile'
2839
displayName: 'Install Dependencies'
40+
condition: ne(variables.CACHE_RESTORED, 'true')
2941

3042
- script: 'yarn build'
3143
displayName: 'Build'
@@ -55,8 +67,56 @@ jobs:
5567
inputs:
5668
versionSpec: '10.x'
5769

58-
- script: 'yarn install'
70+
- task: Cache@2
71+
displayName: 'Check Cache'
72+
inputs:
73+
key: 'yarn | yarn.lock'
74+
path: 'node_modules'
75+
cacheHitVar: CACHE_RESTORED
76+
77+
- script: 'yarn install --frozen-lockfile'
5978
displayName: 'Install Dependencies'
79+
condition: ne(variables.CACHE_RESTORED, 'true')
6080

6181
- script: 'yarn run lint'
6282
displayName: 'Run ESLint'
83+
- job: test
84+
displayName: 'Tests'
85+
86+
pool:
87+
vmImage: 'ubuntu-latest'
88+
89+
steps:
90+
- task: NodeTool@0
91+
displayName: 'Install Node'
92+
inputs:
93+
versionSpec: '10.x'
94+
95+
- task: Cache@2
96+
displayName: 'Check Cache'
97+
inputs:
98+
key: 'yarn | yarn.lock'
99+
path: 'node_modules'
100+
cacheHitVar: CACHE_RESTORED
101+
102+
- script: 'yarn install --frozen-lockfile'
103+
displayName: 'Install Dependencies'
104+
condition: ne(variables.CACHE_RESTORED, 'true')
105+
106+
- script: 'yarn run jest --ci --reporters=default --reporters=jest-junit --coverage'
107+
displayName: 'Run Jest'
108+
109+
- task: PublishTestResults@2
110+
condition: succeededOrFailed()
111+
inputs:
112+
testRunner: JUnit
113+
testResultsFiles: 'junit.xml'
114+
115+
- task: PublishCodeCoverageResults@1
116+
inputs:
117+
codeCoverageTool: Cobertura
118+
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml'
119+
reportDirectory: '$(System.DefaultWorkingDirectory)/coverage'
120+
121+
122+

.eslintrc.yml

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
env:
2-
es6: true
3-
browser: true
2+
es6: true
3+
browser: true
4+
5+
extends:
6+
- "eslint:recommended"
47

58
parserOptions:
6-
ecmaVersion: 6
7-
sourceType: module
9+
ecmaVersion: 6
10+
sourceType: module
811

9-
extends:
10-
- eslint:recommended
12+
overrides:
13+
- files:
14+
"**/*.test.js"
15+
env:
16+
jest: true
17+
extends:
18+
- "plugin:jest/recommended"
19+
- "plugin:jest/style"
20+
plugins:
21+
- jest

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ Generated\ Files/
338338
*.VisualState.xml
339339
TestResult.xml
340340

341+
# JUnit
342+
junit.xml
343+
341344
# Build Results of an ATL Project
342345
[Dd]ebugPS/
343346
[Rr]eleasePS/
@@ -637,4 +640,4 @@ healthchecksdb
637640

638641
# Custom
639642
dist/
640-
docs/
643+
docs/

babel.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current'
8+
}
9+
}
10+
]
11+
]
12+
};

jest.config.js

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
4+
module.exports = {
5+
// All imported modules in your tests should be mocked automatically
6+
// automock: false,
7+
8+
// Stop running tests after `n` failures
9+
// bail: 0,
10+
11+
// Respect "browser" field in package.json when resolving modules
12+
// browser: false,
13+
14+
// The directory where Jest should store its cached dependency information
15+
// cacheDirectory: "/tmp/jest_rs",
16+
17+
// Automatically clear mock calls and instances between every test
18+
clearMocks: true,
19+
20+
// Indicates whether the coverage information should be collected while executing the test
21+
// collectCoverage: false,
22+
23+
// An array of glob patterns indicating a set of files for which coverage information should be collected
24+
// collectCoverageFrom: undefined,
25+
26+
// The directory where Jest should output its coverage files
27+
coverageDirectory: "coverage",
28+
29+
// An array of regexp pattern strings used to skip coverage collection
30+
// coveragePathIgnorePatterns: [
31+
// "/node_modules/"
32+
// ],
33+
34+
// A list of reporter names that Jest uses when writing coverage reports
35+
coverageReporters: [
36+
"cobertura",
37+
],
38+
39+
// An object that configures minimum threshold enforcement for coverage results
40+
// coverageThreshold: undefined,
41+
42+
// A path to a custom dependency extractor
43+
// dependencyExtractor: undefined,
44+
45+
// Make calling deprecated APIs throw helpful error messages
46+
// errorOnDeprecated: false,
47+
48+
// Force coverage collection from ignored files using an array of glob patterns
49+
// forceCoverageMatch: [],
50+
51+
// A path to a module which exports an async function that is triggered once before all test suites
52+
// globalSetup: undefined,
53+
54+
// A path to a module which exports an async function that is triggered once after all test suites
55+
// globalTeardown: undefined,
56+
57+
// A set of global variables that need to be available in all test environments
58+
// globals: {},
59+
60+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
61+
// maxWorkers: "50%",
62+
63+
// An array of directory names to be searched recursively up from the requiring module's location
64+
// moduleDirectories: [
65+
// "node_modules"
66+
// ],
67+
68+
// An array of file extensions your modules use
69+
// moduleFileExtensions: [
70+
// "js",
71+
// "json",
72+
// "jsx",
73+
// "ts",
74+
// "tsx",
75+
// "node"
76+
// ],
77+
78+
// A map from regular expressions to module names that allow to stub out resources with a single module
79+
// moduleNameMapper: {},
80+
81+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
82+
// modulePathIgnorePatterns: [],
83+
84+
// Activates notifications for test results
85+
// notify: false,
86+
87+
// An enum that specifies notification mode. Requires { notify: true }
88+
// notifyMode: "failure-change",
89+
90+
// A preset that is used as a base for Jest's configuration
91+
// preset: undefined,
92+
93+
// Run tests from one or more projects
94+
// projects: undefined,
95+
96+
// Use this configuration option to add custom reporters to Jest
97+
// reporters: undefined,
98+
99+
// Automatically reset mock state between every test
100+
// resetMocks: false,
101+
102+
// Reset the module registry before running each individual test
103+
// resetModules: false,
104+
105+
// A path to a custom resolver
106+
// resolver: undefined,
107+
108+
// Automatically restore mock state between every test
109+
// restoreMocks: false,
110+
111+
// The root directory that Jest should scan for tests and modules within
112+
// rootDir: undefined,
113+
114+
// A list of paths to directories that Jest should use to search for files in
115+
// roots: [
116+
// "<rootDir>"
117+
// ],
118+
119+
// Allows you to use a custom runner instead of Jest's default test runner
120+
// runner: "jest-runner",
121+
122+
// The paths to modules that run some code to configure or set up the testing environment before each test
123+
// setupFiles: [],
124+
125+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
126+
// setupFilesAfterEnv: [],
127+
128+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
129+
// snapshotSerializers: [],
130+
131+
// The test environment that will be used for testing
132+
// testEnvironment: "jest-environment-jsdom",
133+
134+
// Options that will be passed to the testEnvironment
135+
// testEnvironmentOptions: {},
136+
137+
// Adds a location field to test results
138+
// testLocationInResults: false,
139+
140+
// The glob patterns Jest uses to detect test files
141+
// testMatch: [
142+
// "**/__tests__/**/*.[jt]s?(x)",
143+
// "**/?(*.)+(spec|test).[tj]s?(x)"
144+
// ],
145+
146+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
147+
// testPathIgnorePatterns: [
148+
// "/node_modules/"
149+
// ],
150+
151+
// The regexp pattern or array of patterns that Jest uses to detect test files
152+
// testRegex: [],
153+
154+
// This option allows the use of a custom results processor
155+
// testResultsProcessor: undefined,
156+
157+
// This option allows use of a custom test runner
158+
// testRunner: "jasmine2",
159+
160+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
161+
// testURL: "http://localhost",
162+
163+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
164+
// timers: "real",
165+
166+
// A map from regular expressions to paths to transformers
167+
// transform: undefined,
168+
169+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
170+
// transformIgnorePatterns: [
171+
// "/node_modules/"
172+
// ],
173+
174+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
175+
// unmockedModulePathPatterns: undefined,
176+
177+
// Indicates whether each individual test should be reported during the run
178+
// verbose: undefined,
179+
180+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
181+
// watchPathIgnorePatterns: [],
182+
183+
// Whether to use watchman for file crawling
184+
// watchman: true,
185+
};

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
"dependencies": {},
77
"devDependencies": {
88
"@babel/core": "^7.2.2",
9-
"@babel/preset-env": "^7.3.1",
9+
"@babel/preset-env": "^7.9.0",
10+
"babel-jest": "^25.1.0",
1011
"babel-loader": "^8.0.5",
1112
"eslint": "^6.8.0",
13+
"eslint-plugin-jest": "^23.8.2",
14+
"jest": "^25.1.0",
15+
"jest-junit": "^10.0.0",
1216
"jsdoc": "^3.6.3",
1317
"webpack": "^4.29.0",
1418
"webpack-cli": "^3.2.1"
@@ -18,6 +22,7 @@
1822
"dev": "webpack --mode development",
1923
"build": "webpack --mode production",
2024
"lint": "eslint \"src\"",
25+
"test": "jest",
2126
"docs": "jsdoc src -r -R README.md -d docs"
2227
},
2328
"repository": {

tests/index.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import index from '../src/index';
2+
3+
test('contains an ApiClient property', () => {
4+
expect(index).toHaveProperty("ApiClient");
5+
});
6+
7+
test('contains an ApiClientCore property', () => {
8+
expect(index).toHaveProperty("ApiClientCore");
9+
});
10+
11+
test('contains an AppStorage property', () => {
12+
expect(index).toHaveProperty("AppStorage");
13+
});
14+
15+
test('contains an ConnectionManager property', () => {
16+
expect(index).toHaveProperty("ConnectionManager");
17+
});
18+
19+
test('contains an Credentials property', () => {
20+
expect(index).toHaveProperty("Credentials");
21+
});
22+
23+
test('contains an Events property', () => {
24+
expect(index).toHaveProperty("Events");
25+
});

0 commit comments

Comments
 (0)