Skip to content

Commit 6d66c11

Browse files
authored
Add smoke tests (#1614)
1 parent e5bb1ed commit 6d66c11

29 files changed

+10936
-3956
lines changed

.config/karma/base.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const webpackConfigFactory = require('../../webpack.config');
2+
3+
module.exports.create = function(config) {
4+
return {
5+
// base path that will be used to resolve all patterns (eg. files, exclude)
6+
basePath: '',
7+
8+
client: {
9+
clearContext: false,
10+
spec: config.spec
11+
},
12+
13+
// frameworks to use
14+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
15+
frameworks: ['jasmine'],
16+
17+
// list of files / patterns to load in the browser
18+
files: [
19+
'karma.starter.ts',
20+
],
21+
22+
// list of files / patterns to exclude
23+
exclude: [ ],
24+
25+
// preprocess matching files before serving them to the browser
26+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
27+
preprocessors: {
28+
'karma.starter.ts': ['webpack', 'sourcemap'],
29+
},
30+
31+
// test results reporter to use
32+
// possible values: 'dots', 'progress'
33+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
34+
reporters: ['dots'],
35+
36+
// web server port
37+
port: 9876,
38+
39+
// enable / disable colors in the output (reporters and logs)
40+
colors: true,
41+
42+
// level of logging
43+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
44+
logLevel: config.LOG_INFO,
45+
46+
// enable / disable watching file and executing tests whenever any file changes
47+
autoWatch: false,
48+
49+
// start these browsers
50+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
51+
browsers: ['ChromeHeadless', 'FirefoxHeadless'],
52+
53+
// Continuous Integration mode
54+
// if true, Karma captures browsers, runs the tests and exits
55+
singleRun: true,
56+
57+
// Concurrency level
58+
// how many browser should be started simultaneous
59+
concurrency: Infinity,
60+
61+
// Extending timeout fixes https://github.com/handsontable/hyperformula/issues/1430
62+
browserDisconnectTimeout : 60000,
63+
64+
// Webpack's configuration for Karma
65+
webpack: (function() {
66+
// Take the second config from an array - full HF build.
67+
const config = webpackConfigFactory('development')[1];
68+
69+
// Loaders are executed from bottom to top. Push ts-loader as a first loader.
70+
config.module.rules[0].use.push({
71+
loader: 'ts-loader',
72+
options: {
73+
configFile: 'tsconfig.test.json'
74+
}
75+
});
76+
77+
return config;
78+
}()),
79+
};
80+
};

.config/karma/debug.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const configFactory = require('./base');
2+
3+
module.exports.create = function(config) {
4+
const configBase = configFactory.create(config);
5+
6+
return {
7+
...configBase,
8+
browsers: ['Chrome'],
9+
reporters: ['kjhtml'],
10+
singleRun: false,
11+
autoWatch: true,
12+
}
13+
}

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ src/interpreter/plugin/3rdparty
99

1010
# Configurations
1111
*.config.js
12+
karma.*
1213
doc
14+
test/_setupFiles/*.js
1315

1416
# Auto-generated directories
1517
commonjs
@@ -19,5 +21,7 @@ es
1921
languages
2022
lib
2123
script
24+
test-jasmine
25+
test-jest
2226
typedoc
2327
typings

.eslintrc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ module.exports = {
66
'@typescript-eslint',
77
'license-header',
88
'jsdoc',
9+
'jasmine',
10+
'jest',
911
],
1012
env: {
13+
jasmine: true,
14+
'jest/globals': true,
1115
},
1216
parserOptions: {
1317
tsconfigRootDir: __dirname,
@@ -19,6 +23,9 @@ module.exports = {
1923
'plugin:@typescript-eslint/eslint-recommended',
2024
'plugin:@typescript-eslint/recommended',
2125
'plugin:@typescript-eslint/recommended-requiring-type-checking',
26+
'plugin:jasmine/recommended',
27+
'plugin:jest/recommended',
28+
'plugin:jest/style',
2229
],
2330
rules: {
2431
// Automatic fixers
@@ -115,6 +122,13 @@ module.exports = {
115122
MethodDefinition: true,
116123
}
117124
}],
125+
'jest/no-jasmine-globals': 'off',
126+
'jest/no-alias-methods': 'off',
127+
'jest/no-conditional-expect': 'warn',
128+
'jest/no-standalone-expect': 'warn',
129+
'jest/no-test-prefixes': 'off',
130+
'jest/prefer-to-be': 'warn',
131+
'jest/prefer-to-have-length': 'off',
118132
},
119133
overrides: [
120134
{
@@ -129,5 +143,11 @@ module.exports = {
129143
'sort-keys': ['error', 'asc'],
130144
}
131145
},
146+
{
147+
files: ['**/*.spec.ts'],
148+
rules: {
149+
'@typescript-eslint/no-non-null-assertion': 'off',
150+
}
151+
}
132152
],
133153
}

.github/workflows/test.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Test
2+
permissions:
3+
contents: read
4+
5+
on:
6+
pull_request:
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize # the head branch is updated from the base branch, new commits are pushed to the head branch, or the base branch is changed
11+
push:
12+
branches:
13+
- 'master'
14+
- 'develop'
15+
- 'release/**'
16+
17+
jobs:
18+
unit-tests:
19+
strategy:
20+
matrix:
21+
node-version: [ '22' ]
22+
os: [ 'ubuntu-latest' ]
23+
name: unit-tests
24+
runs-on: ${{ matrix.os }}
25+
steps:
26+
- uses: actions/checkout@722adc63f1aa60a57ec37892e133b1d319cae598 # https://github.com/actions/checkout/releases/tag/v2.0.0
27+
28+
- name: Setup Node.js ${{ matrix.node-version }}
29+
uses: actions/setup-node@56899e050abffc08c2b3b61f3ec6a79a9dc3223d # https://github.com/actions/setup-node/releases/tag/v1.4.4
30+
with:
31+
node-version: ${{ matrix.node-version }}
32+
33+
- name: Install dependencies
34+
run: |
35+
npm ci
36+
37+
- name: Run tests
38+
run: |
39+
npm run test:ci
40+
41+
browser-tests:
42+
strategy:
43+
matrix:
44+
node-version: [ '22' ]
45+
os: [ 'ubuntu-latest' ]
46+
name: browser-tests
47+
runs-on: ${{ matrix.os }}
48+
steps:
49+
- uses: actions/checkout@722adc63f1aa60a57ec37892e133b1d319cae598 # https://github.com/actions/checkout/releases/tag/v2.0.0
50+
51+
- name: Setup Node.js ${{ matrix.node-version }}
52+
uses: actions/setup-node@56899e050abffc08c2b3b61f3ec6a79a9dc3223d # https://github.com/actions/setup-node/releases/tag/v1.4.4
53+
with:
54+
node-version: ${{ matrix.node-version }}
55+
56+
- name: Install dependencies
57+
run: |
58+
npm ci
59+
60+
- name: Run tests
61+
run: |
62+
npm run test:browser

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
/es/
1313
/languages/
1414
/lib/
15+
/test-jasmine/
16+
/test-jest/
1517
node_modules/
1618
/typings/
1719
/storage/

.typedoc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
"exclude": [
3+
"./test/**",
34
"./src/interpreter/**",
45
"./src/i18n/**",
56
"./src/parser/**",

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ compile: ## Compile to javascript
99

1010
check: typecheck lint ## Check whether code is working correctly (types + lint)
1111

12-
full: check lint-fix ## Check whether code is ready to commit (types + lint)
12+
test-ci: ## Separate test configuration for CI environment
13+
@npm run test
14+
15+
check: typecheck test ## Check whether code is working correctly (types + specs)
16+
17+
full: check lint-fix ## Check whether code is ready to commit (types + specs + lint)
1318

1419
lint: ## Show linting errors
1520
@npm run lint
@@ -53,6 +58,6 @@ verify-production-licenses:
5358
help: ## Show all make commands
5459
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
5560

56-
.PHONY: doc servedoc
61+
.PHONY: test doc servedoc
5762

5863
.DEFAULT_GOAL := help

docs/guide/building.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ Most likely, you will want to document the code. You can use the following comma
6060
* `npm run docs:build` - builds the docs
6161
* `npm run docs:dev` - serves the development version of the docs locally
6262

63+
## Run the tests
64+
65+
The tests are done with Jest and Karma. The same test suite should
66+
pass in both of them because the library might be used
67+
[server-side](server-side-installation) or in a browser, so you have
68+
to be sure that both environments are fine.
69+
70+
* `npm run test` - runs the linter and all tests
71+
* `npm run test:jest` - runs unit tests
72+
* To run a test suite that matches a word, add a Jest `-t` flag. For example: `npm run test:jest -- -t 'SUMIF'` runs only the tests that match the word `SUMIF` within `describe()` or `it()`.
73+
* To run a specific test suite, pass the file name. For example: `npm run test:jest 'function-sumif.spec.ts'` runs only the unit tests from the file `function-sumif.spec.ts`.
74+
* `npm run test:browser` - runs tests in **karma** once and closes all open browsers
75+
* To run a specific `spec` file or a test suite you can add a Karma `--spec` flag. For example: `npm run test:browser.debug -- --spec=matrix.spec.ts` runs `matrix.spec.ts` browser tests only
76+
* `npm run test:browser.debug` - runs test in **karma** only in Chrome until you exit the process. It watches changes in `src` and `test` directories and rebuilds them automatically.
77+
6378
## Run the linter
6479

6580
You can use the following commands to lint the code, so it meets the required standards. ESLint is used as the tool of choice in this case.

jasmine.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"spec_dir": "test-jasmine/test",
3+
"spec_files": [
4+
"**/*[sS]pec.js"
5+
],
6+
"helpers": [
7+
"_setupFiles/babel.js",
8+
"_setupFiles/bootstrap.js",
9+
"_setupFiles/jsdom.js"
10+
],
11+
"stopSpecOnExpectationFailure": false,
12+
"random": true
13+
}

0 commit comments

Comments
 (0)