Skip to content

Commit

Permalink
Migrate unit tests to jest (#162)
Browse files Browse the repository at this point in the history
* Migrate test framework to Jest

* Format source files with prettify

* Bump CI node version to 20.x

---------

Co-authored-by: Silvia Chen <[email protected]>
  • Loading branch information
silviac98 and Silvia Chen authored Jan 29, 2025
1 parent 9667a65 commit 688efe7
Show file tree
Hide file tree
Showing 51 changed files with 22,998 additions and 15,641 deletions.
31 changes: 23 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*!
* Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT
*/

module.exports = {
extends: [
Expand All @@ -6,14 +10,25 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
],
plugins: ['@typescript-eslint'],

rules: {
"@typescript-eslint/return-await": 'off',
"@typescript-eslint/no-inferrable-types": 'warn',
"@typescript-eslint/no-explicit-any": 'warn',
'@typescript-eslint/no-explicit-any': 'off',
'no-console': 'warn',
'prefer-const': 'warn',
'no-useless-escape': 'warn'
'@typescript-eslint/no-unused-vars': [
'warn',
{
caughtErrors: 'none',
argsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true,
},
],
},
ignorePatterns: ['*.js', '*.d.ts', 'node_modules/'],
}
ignorePatterns: ['*.js', '*.d.ts', 'node_modules/', 'src/tests/yaml-strings', 'src/tests/json-strings'],
}

10 changes: 6 additions & 4 deletions .github/workflows/compile-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ name: compile-lint-test

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]
# To avoid compatibility problems, pin the CI node.js version to node version used by VSCode Electron
# so integration testing will not rely on a later version of node than exists in the default VS Code execution env.
# Full table with details here: https://github.com/ewanharris/vscode-versions
node-version: [20.x]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules
out
coverage
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lint-staged
4 changes: 4 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*.{js,yml,json,md}": "prettier --write",
"*.ts": ["eslint --fix", "prettier --write"]
}
3 changes: 0 additions & 3 deletions .mocharc.yml

This file was deleted.

9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "http://json.schemastore.org/prettierrc",
"tabWidth": 2,
"trailingComma": "all",
"semi": false,
"useTabs": false,
"singleQuote": true,
"printWidth": 120
}
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
}
29 changes: 29 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*!
* Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT
*/

/** @type {import('ts-jest').JestConfigWithTsJest} */

const transformCodeInPackages = []

module.exports = {
preset: 'ts-jest',
testMatch: ['**/src/**/?(*.)+(spec|test).ts'],

coverageReporters: ['cobertura', 'html', 'text'],
collectCoverageFrom: ['src/**/*.ts'],
coveragePathIgnorePatterns: ['^.*/scripts/.*$', '^.*/schema/.*$', '^.*/tests/.*$', 'interface.ts'],
transformIgnorePatterns: [`<rootDir>/node_modules/(?!${transformCodeInPackages.join('|')}).+\\.js$`],
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': [
'babel-jest',
{
presets: ['@babel/preset-env'],
plugins: [['@babel/transform-runtime']],
},
],
},
clearMocks: true,
}
Loading

0 comments on commit 688efe7

Please sign in to comment.