Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .config/karma/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const webpackConfigFactory = require('../../webpack.config');

module.exports.create = function(config) {
return {
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

client: {
clearContext: false,
spec: config.spec
},

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],

// list of files / patterns to load in the browser
files: [
'karma.starter.ts',
],

// list of files / patterns to exclude
exclude: [ ],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'karma.starter.ts': ['webpack', 'sourcemap'],
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['dots'],

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['ChromeHeadless', 'FirefoxHeadless'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,

// Extending timeout fixes https://github.com/handsontable/hyperformula/issues/1430
browserDisconnectTimeout : 60000,

// Webpack's configuration for Karma
webpack: (function() {
// Take the second config from an array - full HF build.
const config = webpackConfigFactory('development')[1];

// Loaders are executed from bottom to top. Push ts-loader as a first loader.
config.module.rules[0].use.push({
loader: 'ts-loader',
options: {
configFile: 'tsconfig.test.json'
}
});

return config;
}()),
};
};
13 changes: 13 additions & 0 deletions .config/karma/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const configFactory = require('./base');

module.exports.create = function(config) {
const configBase = configFactory.create(config);

return {
...configBase,
browsers: ['Chrome'],
reporters: ['kjhtml'],
singleRun: false,
autoWatch: true,
}
}
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ src/interpreter/plugin/3rdparty

# Configurations
*.config.js
karma.*
doc
test/_setupFiles/*.js

# Auto-generated directories
commonjs
Expand All @@ -19,5 +21,7 @@ es
languages
lib
script
test-jasmine
test-jest
typedoc
typings
22 changes: 21 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@ module.exports = {
'@typescript-eslint',
'license-header',
'jsdoc',
'jasmine',
'jest',
],
env: {
jasmine: true,
'jest/globals': true,
},
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json',
project: './tsconfig.test.json',
createDefaultProgram: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:jasmine/recommended',
'plugin:jest/recommended',
'plugin:jest/style',
],
rules: {
// Automatic fixers
Expand Down Expand Up @@ -115,6 +122,13 @@ module.exports = {
MethodDefinition: true,
}
}],
'jest/no-jasmine-globals': 'off',
'jest/no-alias-methods': 'off',
'jest/no-conditional-expect': 'warn',
'jest/no-standalone-expect': 'warn',
'jest/no-test-prefixes': 'off',
'jest/prefer-to-be': 'warn',
'jest/prefer-to-have-length': 'off',
},
overrides: [
{
Expand All @@ -129,5 +143,11 @@ module.exports = {
'sort-keys': ['error', 'asc'],
}
},
{
files: ['**/*.spec.ts'],
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
}
}
],
}
62 changes: 62 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Test
permissions:
contents: read

on:
pull_request:
types:
- opened
- reopened
- synchronize # the head branch is updated from the base branch, new commits are pushed to the head branch, or the base branch is changed
push:
branches:
- 'master'
- 'develop'
- 'release/**'

jobs:
unit-tests:
strategy:
matrix:
node-version: [ '22' ]
os: [ 'ubuntu-latest' ]
name: unit-tests
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@722adc63f1aa60a57ec37892e133b1d319cae598 # https://github.com/actions/checkout/releases/tag/v2.0.0

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@56899e050abffc08c2b3b61f3ec6a79a9dc3223d # https://github.com/actions/setup-node/releases/tag/v1.4.4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: |
npm ci

- name: Run tests
run: |
npm run test:ci

browser-tests:
strategy:
matrix:
node-version: [ '22' ]
os: [ 'ubuntu-latest' ]
name: browser-tests
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@722adc63f1aa60a57ec37892e133b1d319cae598 # https://github.com/actions/checkout/releases/tag/v2.0.0

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@56899e050abffc08c2b3b61f3ec6a79a9dc3223d # https://github.com/actions/setup-node/releases/tag/v1.4.4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: |
npm ci

- name: Run tests
run: |
npm run test:browser
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
/es/
/languages/
/lib/
/test-jasmine/
/test-jest/
node_modules/
/typings/
/storage/
Expand Down
1 change: 1 addition & 0 deletions .typedoc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
"exclude": [
"./test/**",
"./src/interpreter/**",
"./src/i18n/**",
"./src/parser/**",
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ setup: ## Setup project
compile: ## Compile to javascript
@npm run compile

check: typecheck lint ## Check whether code is working correctly (types + lint)
test: ## Run tests
@npm run test

full: check lint-fix ## Check whether code is ready to commit (types + lint)
test-ci: ## Separate test configuration for CI environment
@npm run test

check: typecheck test ## Check whether code is working correctly (types + specs)

full: check lint-fix ## Check whether code is ready to commit (types + specs + lint)

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

.PHONY: doc servedoc
.PHONY: test doc servedoc

.DEFAULT_GOAL := help
15 changes: 15 additions & 0 deletions docs/guide/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ Most likely, you will want to document the code. You can use the following comma
* `npm run docs:build` - builds the docs
* `npm run docs:dev` - serves the development version of the docs locally

## Run the tests

The tests are done with Jest and Karma. The same test suite should
pass in both of them because the library might be used
[server-side](server-side-installation) or in a browser, so you have
to be sure that both environments are fine.

* `npm run test` - runs the linter and all tests
* `npm run test:jest` - runs unit tests
* 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()`.
* 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`.
* `npm run test:browser` - runs tests in **karma** once and closes all open browsers
* 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
* `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.

## Run the linter

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.
Expand Down
13 changes: 13 additions & 0 deletions jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"spec_dir": "test-jasmine/test",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"_setupFiles/babel.js",
"_setupFiles/bootstrap.js",
"_setupFiles/jsdom.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}
60 changes: 60 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: [
'src/**',
'!**/node_modules/**',
],

coverageProvider: 'babel',

// The directory where Jest should output its coverage files
coverageDirectory: "coverage",

// A path to a module which exports an async function that is triggered once before all test suites
globalSetup: '<rootDir>/test/_setupFiles/globalSetup.ts',

// A set of global variables that need to be available in all test environments
globals: {
"ts-jest": {
"tsconfig": "./test/tsconfig.json"
}
},

// An array of file extensions your modules use
moduleFileExtensions: [
"ts",
"tsx",
"js"
],

// The paths to modules that run some code to configure or set up the testing environment after each test
setupFilesAfterEnv: [
'<rootDir>/test/_setupFiles/bootstrap.ts',
'<rootDir>/test/_setupFiles/jest/bootstrap.ts'
],

// The test environment that will be used for testing
testEnvironment: "node",

// The glob patterns Jest uses to detect test files
testMatch: [
"<rootDir>/test/**/*spec.(ts|js)"
],

silent: true,

// A map from regular expressions to paths to transformers
transform: {
"^.+\\.(ts|tsx)$": "ts-jest"
},

watchPathIgnorePatterns: [
'/node_modules/',
'/dist/',
'/commonjs/',
'/es/',
]
};
8 changes: 8 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const env = process.env.NODE_ENV || 'base';
const configFactory = require(`./.config/karma/${env}`);

module.exports = function(config) {
config.set(
configFactory.create(config)
);
};
17 changes: 17 additions & 0 deletions karma.starter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import './test/_setupFiles/bootstrap';

//@ts-ignore
const specArg: string = __karma__.config.spec;

// require all modules ending in ".spec.ts" from the
// './test' directory and all subdirectories
const testsContext = require.context('./test', true, /.spec.ts$/);
let files = testsContext.keys();

if (specArg) {
const regEx = new RegExp(specArg);

files = testsContext.keys().filter(key => key.match(regEx));
}

files.forEach(testsContext);
Loading
Loading