I've been experimenting with incorporating Typescript into my detox tests. The most relevant information I could find was in this gist. However, when trying to implement it, I encountered an error stating that jasmine is not defined. After researching Detox's issues, I discovered that they currently only support jest-circus (https://github.com/wix/Detox/issues/2469). Could this be related to the fact that I'm having difficulty using ts-jest
? Is there a way to write my tests with Typescript?
Would anyone be able to provide an updated example of how to set it up in a typescript project?
Here's what I have so far:
e2e/config.json
{
"maxWorkers": 1,
"testRunner": "jest-circus/runner",
"testTimeout": 120000,
"testRegex": "\\.e2e\\.ts$",
"reporters": ["detox/runners/jest/streamlineReporter"],
"verbose": true,
"preset": "ts-jest",
"testEnvironment": "node",
"setupTestFrameworkScriptFile": "./init.ts"
}
e2e/enviroment.js
const {
DetoxCircusEnvironment,
SpecReporter,
WorkerAssignReporter,
} = require('detox/runners/jest-circus')
class CustomDetoxEnvironment extends DetoxCircusEnvironment {
constructor(config, context) {
super(config, context)
// Can be safely removed, if you are content with the default value (=300000ms)
this.initTimeout = 300000
// This takes care of generating status logs on a per-spec basis. By default, Jest only reports at file-level.
// This is strictly optional.
this.registerListeners({
SpecReporter,
WorkerAssignReporter,
})
}
}
module.exports = CustomDetoxEnvironment
e2e/init.ts
import {cleanup, init} from 'detox'
import 'jasmine'
const config = require('../package.json').detox as Detox.DetoxConfig
const adapter = require('detox/runners/jest/adapter')
// eslint-disable-next-line no-magic-numbers
jest.setTimeout(120000)
jasmine.getEnv().addReporter(adapter)
beforeAll(async () => {
await init(config, {initGlobals: false})
})
beforeEach(async () => {
await adapter.beforeEach()
})
afterAll(async () => {
await adapter.afterAll()
await cleanup()
})
Dev dependencies on package.json
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"@types/jasmine": "^3.10.3",
"@types/jest": "^27.4.1",
"@types/lodash.debounce": "^4.0.6",
"@types/lodash.unescape": "^4.0.6",
"@types/react-native": "^0.67.1",
...
}
The current error I am facing is:
Cannot find module 'jasmine' from 'init.ts'