Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests #18

Merged
merged 17 commits into from
Jan 23, 2024
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
3 changes: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PRODUCTION_ENVIRONMENT_ID=
EXPORT_IMPORT_TEST_DATA_ENVIRONMENT_ID=
API_KEY=
26 changes: 23 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
{
"extends": [
"@kontent-ai"
]
"extends": [
"@kontent-ai"
],

"overrides": [
{
"files": ["src/**/*.ts"],
"excludedFiles": ["src/log.ts"],
"rules": {
"no-restricted-syntax": [
"error",
{
"selector": "MemberExpression[object.name='console'][property.name=/^(log|warn|error|info|trace)$/]",
"message": "Don't log into the console directly. Use one of the functions from the log.ts file (logInfo, logWarning, logError) to ensure provided --logLevel is respected."
}
]
}
}
],

"parserOptions": {
"project": ["tsconfig.json", "tsconfig.tests.jsonc", "tsconfig.configs.jsonc"]
}
}
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint & build
name: Lint & Build

on:
push:
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/integrationTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run Integration Tests

on:
push:
branches: [main]
pull_request:

env:
PRODUCTION_ENVIRONMENT_ID: ${{ secrets.PRODUCTION_ENVIRONMENT_ID }}
EXPORT_IMPORT_TEST_DATA_ENVIRONMENT_ID: ${{ secrets.EXPORT_IMPORT_TEST_DATA_ENVIRONMENT_ID }}
API_KEY: ${{ secrets.API_KEY }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js from .nvmrc file
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- run: npm ci
- run: npm run test:integration
18 changes: 18 additions & 0 deletions .github/workflows/unitTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Run Unit Tests

on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js from .nvmrc file
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- run: npm ci
- run: npm run test:unit
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Build output
build/

# Tests tmp data
tests/integration/importExport/data/exportedData.zip

# MacOS
.DS_Store

Expand Down
3 changes: 2 additions & 1 deletion dprint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "https://raw.githubusercontent.com/kontent-ai/dprint-config/main/dprint.json",
"includes": [
"src/**/*.{ts,tsx,js,jsx,json}"
"src/**/*.{ts,tsx,js,jsx,json}",
"tests/**/*.{ts,tsx,js,jsx,json}"
]
}
18 changes: 18 additions & 0 deletions jestIntegrationTests.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { JestConfigWithTsJest } from 'ts-jest'

const minute = 60_000;

const jestConfig: JestConfigWithTsJest = {
preset: 'ts-jest',
testEnvironment: 'node',
rootDir: "tests/integration",
resolver: "../../jestModuleResolver.cjs",
testTimeout: 5 * minute,
transform: {
".*": ["ts-jest", {
tsconfig: "tsconfig.tests.jsonc"
}]
},
}

export default jestConfig
15 changes: 15 additions & 0 deletions jestModuleResolver.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const moduleResolver = (path, options) => {
const jsExtRegex = /\.js$/i
const resolver = options.defaultResolver
if (jsExtRegex.test(path)) {
try {
return resolver(path.replace(jsExtRegex, '.ts'), options)
} catch {
// use default resolver
}
}

return resolver(path, options)
};

module.exports = moduleResolver;
16 changes: 16 additions & 0 deletions jestUnitTests.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { JestConfigWithTsJest } from 'ts-jest'

const jestConfig: JestConfigWithTsJest = {
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
rootDir: "tests/unit",
resolver: "../../jestModuleResolver.cjs",
transform: {
".*": ["ts-jest", {
useESM: true,
tsconfig: "tsconfig.tests.jsonc"
}]
},
}

export default jestConfig
Loading