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

ERR_UNKNOWN_FILE_EXTENSION reason: Unknown file extension ".ts" #109

Closed
alexbjorlig opened this issue Jun 27, 2022 · 1 comment
Closed

Comments

@alexbjorlig
Copy link

Our team upgraded our mono-repo, and moved some dependencies to a package. Now our globalSetup file throws the following error:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Jest: Got error running globalSetup - <path-to-project>/apps/web-app/integration-tests/integration-global-setup.ts, reason: Unknown file extension ".ts" for <path-to-project>/apps/web-app/integration-tests/integration-global-setup.ts

Our integration-tests are written in a ESM module.

.swcrc

{
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "tsx": false,
            "decorators": false,
            "dynamicImport": true,
            "importMeta": false
        }
    }
}

jest.config.integration.cjs

module.exports = {
    roots: ['integration-tests'],
    watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
    testEnvironment: 'node',
    transform: {
        '^.+\\.(t|j)sx?$': [
            '@swc/jest',
            {
                jsc: {
                    target: 'es2021',
                },
            },
        ],
    },
    setupFiles: ['<rootDir>/src/helpers/test-helpers/global-before-all-jest-integration.ts'],
    globalSetup: '<rootDir>/integration-tests/integration-global-setup.ts',
    testMatch: ['**/?(*.)+(spec|test).ts'],
    transformIgnorePatterns: [],
    moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
    globals: {
        'ts-jest': {
            tsconfig: 'tsconfig.spec.json',
        },
    },
    testTimeout: 20000,
};

integration-global-setup.ts

import fetch from 'node-fetch';
import { testHelpersGetDb } from './helpers/test-helpers-get-db';
import { syncIndexesToDb } from '@eddy/core/src/db/sync-indexes-to-db'; // <== Fails with this line of code

async function eddySleep(durationInMs: number): Promise<void> {
    return new Promise((resolve) => {
        setTimeout(() => resolve(), durationInMs);
    });
}

let didIndexesSync: Promise<any>;

export default async function integrationGlobalSetup() {
    try {
@alexbjorlig
Copy link
Author

It was related to not being able to use .ts in global teardown/setup files kulshekhar/ts-jest#411 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant