Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
68 changes: 57 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,78 @@
name: Test

on:
pull_request:
branches:
- main
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
test:
name: Test
timeout-minutes: 20
determine-packages:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.set-packages.outputs.packages }}
steps:
- uses: actions/checkout@v4
- name: Get package names
id: set-packages
run: |
SEARCH_DIRS="plugins utils validate convert enrich import export"

PACKAGES=$(
for dir in $SEARCH_DIRS; do
if [ -d "$dir" ]; then
find "$dir" -maxdepth 2 -name "package.json" -exec sh -c '
PACKAGE_NAME=$(jq -r .name {})
if [ "$PACKAGE_NAME" != "null" ]; then
echo "$PACKAGE_NAME"
fi
' \;
fi
done | jq -R -s -c 'split("\n")[:-1]'
)

echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
echo "Found packages: $PACKAGES"

test-packages:
needs: determine-packages
name: Test (${{ matrix.package }})
runs-on: ubuntu-latest
if: ${{ github.head_ref != 'changeset-release/main' }}
strategy:
matrix:
package: ${{fromJson(needs.determine-packages.outputs.packages)}}
fail-fast: false
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2
uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build
run: npx turbo run build

- name: Test
run: npm run test
run: npx turbo run test --filter=${{ matrix.package }}

test:
needs: test-packages
name: Test
runs-on: ubuntu-latest
steps:
- name: Check test results
run: |
echo "All package tests completed successfully"
exit 0
16 changes: 16 additions & 0 deletions convert/what3words/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: 'node',

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
setupFiles: ['../../test/dotenv-config.js'],
setupFilesAfterEnv: [
'../../test/betterConsoleLog.js',
'../../test/unit.cleanup.js',
],
testTimeout: 60_000,
globalSetup: '../../test/setup-global.js',
forceExit: true,
passWithNoTests: true,
}
4 changes: 2 additions & 2 deletions convert/what3words/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"build:watch": "rollup -c --watch",
"build:prod": "NODE_ENV=production rollup -c",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
"test": "jest src/*.spec.ts"
},
"keywords": [
"flatfile-plugins",
Expand All @@ -60,4 +60,4 @@
"devDependencies": {
"@flatfile/rollup-config": "0.1.1"
}
}
}
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
testEnvironment: 'node',
testRegex: '.*\\.(e2e-)?spec\\.ts$',
// testRegex: '(?<!\\.\\./)src/.*\\.(e2e-)?spec\\.ts$',
testMatch: ['<rootDir>/**/**/src/*.spec.ts'],

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
Expand All @@ -12,4 +14,5 @@ module.exports = {
testTimeout: 60_000,
globalSetup: '<rootDir>/test/setup-global.js',
forceExit: true,
passWithNoTests: true,
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
],
"scripts": {
"clean": "find ./ '(' -name 'node_modules' -o -name 'dist' -o -name '.turbo' -o -name '.parcel-cache' ')' -type d -exec rm -rf {} +",
"test": "turbo build && turbo test --concurrency=1",
"test": "jest --config=./jest.config.js --runInBand",
"build": "turbo build",
"turbo:test": "turbo test",
"build:prod": "turbo build:prod",
"build:clean": "npm run clean && npm i && turbo build",
"build:prod:clean": "npm run clean && npm i && turbo build:prod",
Expand Down
16 changes: 16 additions & 0 deletions plugins/autocast/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: 'node',

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
setupFiles: ['../../test/dotenv-config.js'],
setupFilesAfterEnv: [
'../../test/betterConsoleLog.js',
'../../test/unit.cleanup.js',
],
testTimeout: 60_000,
globalSetup: '../../test/setup-global.js',
forceExit: true,
passWithNoTests: true,
Comment on lines +14 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Issues Detected:

  1. Jest Execution Failed: The npx command is not found, preventing Jest from running. Ensure that Jest is installed and that npx is available in the environment.
  2. No Test Files Found: No test files (*.test.ts or *.test.js) are present in the repository. This makes the passWithNoTests: true setting potentially problematic, as it allows the test suite to pass without executing any tests.
🔗 Analysis chain

Review the necessity of forceExit and passWithNoTests options.

While these options can be useful in certain scenarios, they may mask underlying issues:

  1. forceExit: true forces Jest to exit after all tests complete. This can hide problems with asynchronous operations or resources not being properly closed.

  2. passWithNoTests: true allows the test suite to pass when no tests are found. This might lead to false confidence if tests are accidentally skipped or not written.

Let's investigate if these options are necessary:

Consider removing these options if possible, and address any underlying issues they might be masking. If they are necessary, add comments explaining why they are needed to prevent future confusion.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for hanging handles and test file presence

# Test: Run Jest without forceExit and check for hanging handles
npx jest --detectOpenHandles

# Check for test files
find . -name "*.test.ts" -o -name "*.test.js" | wc -l

Length of output: 159

}
2 changes: 1 addition & 1 deletion plugins/autocast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"build:watch": "rollup -c --watch",
"build:prod": "NODE_ENV=production rollup -c",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
"test": "jest src/*.spec.ts"
},
"keywords": [
"flatfile-plugins",
Expand Down
16 changes: 16 additions & 0 deletions plugins/automap/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: 'node',

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
setupFiles: ['../../test/dotenv-config.js'],
setupFilesAfterEnv: [
'../../test/betterConsoleLog.js',
'../../test/unit.cleanup.js',
],
testTimeout: 90_000,
globalSetup: '../../test/setup-global.js',
forceExit: true,
passWithNoTests: true,
}
2 changes: 1 addition & 1 deletion plugins/automap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build:watch": "parcel watch",
"build:prod": "NODE_ENV=production parcel build",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
"test": "jest src/*.spec.ts"
},
"keywords": [
"flatfile-plugins",
Expand Down
16 changes: 16 additions & 0 deletions plugins/constraints/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: 'node',

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
setupFiles: ['../../test/dotenv-config.js'],
setupFilesAfterEnv: [
'../../test/betterConsoleLog.js',
'../../test/unit.cleanup.js',
],
testTimeout: 60_000,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Reduce the testTimeout value to better match actual test durations.

The current testTimeout is set to 60,000ms (60 seconds), but all monitored tests complete well below this threshold (maximum recorded duration is 17ms). Reducing the timeout will streamline the testing process and ensure quicker feedback.

  • Update testTimeout in plugins/constraints/jest.config.js from 60_000 to 10_000 or an appropriate lower value based on your testing needs.
🔗 Analysis chain

Consider reviewing the need for a 60-second test timeout.

The testTimeout is set to 60 seconds, which is quite long for unit tests. While this may be necessary for some complex operations or network requests, it's worth verifying if all tests require this extended timeout.

To help determine if this timeout is necessary, we can check for long-running tests:

This script will help identify any tests that take longer than 10 seconds to run, which might justify the 60-second timeout.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for test files and analyze their execution time
fd -e test.ts -e spec.ts -e test.js -e spec.js | xargs grep -H "test(" | while read -r line; do
    file=$(echo "$line" | cut -d':' -f1)
    test_name=$(echo "$line" | sed -E 's/.*test\((.*)\).*/\1/')
    echo "Running test: $test_name in $file"
    start_time=$(date +%s%N)
    npx jest "$file" -t "$test_name" > /dev/null 2>&1
    end_time=$(date +%s%N)
    duration=$(( (end_time - start_time) / 1000000 ))
    if [ $duration -gt 10000 ]; then
        echo "Long-running test detected: $test_name in $file (${duration}ms)"
    fi
done

Length of output: 23582

globalSetup: '../../test/setup-global.js',
forceExit: true,
passWithNoTests: true,
}
2 changes: 1 addition & 1 deletion plugins/constraints/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"build:watch": "rollup -c --watch",
"build:prod": "NODE_ENV=production rollup -c",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
"test": "jest src/*.spec.ts"
},
"keywords": [],
"author": "David Boskovic",
Expand Down
4 changes: 3 additions & 1 deletion plugins/constraints/src/external.constraint.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ describe('externalConstraint()', () => {

it('correctly assigns an error', async () => {
await createRecords(sheetId, defaultSimpleValueData)
await listener.waitFor('commit:created')
await listener.waitFor('commit:created', 2)
// Sleep for 1000ms to allow time for the constraint to be applied
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Consider addressing the potential timing issue without using sleep.

The comment suggests adding a sleep to allow time for the constraint to be applied. This indicates a potential race condition or timing issue in the test or implementation.

Instead of using an arbitrary sleep, consider these alternatives:

  1. Implement a polling mechanism to check for the constraint application.
  2. Add an event or callback when the constraint is fully applied.
  3. Refactor the implementation to ensure synchronous constraint application if possible.

These approaches would make the test more reliable and faster than using a sleep.

// await new Promise(resolve => setTimeout(resolve, 1000));
const records = await getRecords(sheetId)
expect(records[0].values['name'].messages[0]).toMatchObject({
type: 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('externalConstraint()', () => {
it('correctly handles thrown errors', async () => {
await createRecords(sheetId, defaultSimpleValueData)

await listener.waitFor('commit:created')
await listener.waitFor('commit:created', 2)
const records = await getRecords(sheetId)
expect(records[0].values['name'].messages[0]).toMatchObject({
type: 'error',
Expand Down
16 changes: 16 additions & 0 deletions plugins/dedupe/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: 'node',

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
setupFiles: ['../../test/dotenv-config.js'],
setupFilesAfterEnv: [
'../../test/betterConsoleLog.js',
'../../test/unit.cleanup.js',
],
testTimeout: 60_000,
globalSetup: '../../test/setup-global.js',
forceExit: true,
passWithNoTests: true,
Comment on lines +14 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider the implications of forceExit and passWithNoTests.

While these options can be useful in certain scenarios, they might mask underlying issues:

  1. forceExit: true forces Jest to exit after tests complete. This can hide cleanup problems or hanging handles.
  2. passWithNoTests: true allows the suite to pass when no tests are found, which could potentially hide issues if tests are accidentally skipped or not detected.

Consider the following alternatives:

  1. Instead of forceExit, try to identify and fix any hanging handles or cleanup issues.
  2. For passWithNoTests, consider setting this to false in your CI pipeline to catch cases where tests are accidentally skipped or not detected.

If these options are necessary for specific reasons, please add comments explaining why they are needed.

}
2 changes: 1 addition & 1 deletion plugins/dedupe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"build:watch": "rollup -c --watch",
"build:prod": "NODE_ENV=production rollup -c",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
"test": "jest src/*.spec.ts"
},
"keywords": [
"flatfile-plugins",
Expand Down
16 changes: 16 additions & 0 deletions plugins/delimiter-extractor/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: 'node',

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
setupFiles: ['../../test/dotenv-config.js'],
setupFilesAfterEnv: [
'../../test/betterConsoleLog.js',
'../../test/unit.cleanup.js',
],
testTimeout: 60_000,
globalSetup: '../../test/setup-global.js',
forceExit: true,
passWithNoTests: true,
}
2 changes: 1 addition & 1 deletion plugins/delimiter-extractor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build:watch": "parcel watch",
"build:prod": "NODE_ENV=production parcel build",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
"test": "jest src/*.spec.ts"
},
"keywords": [
"flatfile-plugins",
Expand Down
16 changes: 16 additions & 0 deletions plugins/dxp-configure/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: 'node',

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
setupFiles: ['../../test/dotenv-config.js'],
setupFilesAfterEnv: [
'../../test/betterConsoleLog.js',
'../../test/unit.cleanup.js',
],
testTimeout: 60_000,
globalSetup: '../../test/setup-global.js',
forceExit: true,
passWithNoTests: true,
}
2 changes: 1 addition & 1 deletion plugins/dxp-configure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"build:watch": "rollup -c --watch",
"build:prod": "NODE_ENV=production rollup -c",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
"test": "jest src/*.spec.ts"
},
"keywords": [
"flatfile-plugins",
Expand Down
16 changes: 16 additions & 0 deletions plugins/export-workbook/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: 'node',

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
setupFiles: ['../../test/dotenv-config.js'],
setupFilesAfterEnv: [
'../../test/betterConsoleLog.js',
'../../test/unit.cleanup.js',
],
testTimeout: 60_000,
globalSetup: '../../test/setup-global.js',
forceExit: true,
passWithNoTests: true,
}
16 changes: 16 additions & 0 deletions plugins/foreign-db-extractor/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: 'node',

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
setupFiles: ['../../test/dotenv-config.js'],
setupFilesAfterEnv: [
'../../test/betterConsoleLog.js',
'../../test/unit.cleanup.js',
],
testTimeout: 60_000,
globalSetup: '../../test/setup-global.js',
forceExit: true,
passWithNoTests: true,
}
16 changes: 16 additions & 0 deletions plugins/graphql-schema/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: 'node',

transform: {
'^.+\\.tsx?$': 'ts-jest',
},
setupFiles: ['../../test/dotenv-config.js'],
setupFilesAfterEnv: [
'../../test/betterConsoleLog.js',
'../../test/unit.cleanup.js',
],
testTimeout: 60_000,
globalSetup: '../../test/setup-global.js',
forceExit: true,
passWithNoTests: true,
}
2 changes: 1 addition & 1 deletion plugins/graphql-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"build:watch": "rollup -c --watch",
"build:prod": "NODE_ENV=production rollup -c",
"check": "tsc ./**/*.ts --noEmit --esModuleInterop",
"test": "jest ./**/*.spec.ts --config=../../jest.config.js --runInBand"
"test": "jest src/*.spec.ts"
},
"keywords": [],
"author": "Flatfile, Inc.",
Expand Down
Loading