From 1690329bf7e14a1e70624535b2fe6e3eeeeb752c Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Fri, 13 May 2022 16:34:31 +0300 Subject: [PATCH] docs: update docs --- detox/package.json | 1 + detox/src/configuration/composeAppsConfig.js | 2 +- detox/src/utils/callsites.test.js | 15 +++++++-------- detox/src/utils/errorUtils.test.js | 10 +++++++--- docs/Guide.Jest.md | 5 +---- examples/demo-react-native-jest/package.json | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/detox/package.json b/detox/package.json index 5a79a50af6..b49280c1a0 100644 --- a/detox/package.json +++ b/detox/package.json @@ -75,6 +75,7 @@ "which": "^1.3.1", "ws": "^7.0.0", "yargs": "^16.0.3", + "yargs-parser": "^20.2.2", "yargs-unparser": "^2.0.0" }, "peerDependencies": { diff --git a/detox/src/configuration/composeAppsConfig.js b/detox/src/configuration/composeAppsConfig.js index 4ad6a410a5..5e72d0dab7 100644 --- a/detox/src/configuration/composeAppsConfig.js +++ b/detox/src/configuration/composeAppsConfig.js @@ -1,6 +1,6 @@ // @ts-nocheck const _ = require('lodash'); -const parse = require('yargs/yargs').Parser; +const parse = require('yargs-parser'); const deviceAppTypes = require('./utils/deviceAppTypes'); diff --git a/detox/src/utils/callsites.test.js b/detox/src/utils/callsites.test.js index 3fa1d7fbaf..b72f6e53e0 100644 --- a/detox/src/utils/callsites.test.js +++ b/detox/src/utils/callsites.test.js @@ -27,20 +27,19 @@ describe('callsites', () => { const callStackDumpFromWrapperFn = (endFrame) => callsites.getStackDump(endFrame); const callStackDumpFromTwoWrapperFn = (endFrame) => callStackDumpFromWrapperFn(endFrame); - const expectedTopFrameRegExp = /^ {4}at callStackDumpFromWrapperFn \(src[\\/]utils[\\/]callsites\.test\.js:[0-9][0-9]?:[0-9][0-9]?\)/; - const expected2ndLineRegExp = /^ {4}at callStackDumpFromTwoWrapperFn \(src[\\/]utils[\\/]callsites\.test\.js:[0-9][0-9]?:[0-9][0-9]?\)/; + const expectedTopFrameRegExp = /^ {4}at (?:Object\.)?callStackDumpFromWrapperFn \(src[\\/]utils[\\/]callsites\.test\.js:[0-9][0-9]?:[0-9][0-9]?\)/; + const expected2ndLineRegExp = /^ {4}at (?:Object\.)?callStackDumpFromTwoWrapperFn \(src[\\/]utils[\\/]callsites\.test\.js:[0-9][0-9]?:[0-9][0-9]?\)/; it('should return a valid, multi-line, stack-dump string', () => { - const stackdump = callStackDumpFromTwoWrapperFn(); + const [,line1,line2] = callStackDumpFromTwoWrapperFn().split('\n'); - expect(stackdump).toEqual(expect.stringMatching(expectedTopFrameRegExp)); - expect(stackdump).toEqual(expect.stringMatching(new RegExp(expected2ndLineRegExp, 'm'))); + expect(line1).toEqual(expect.stringMatching(expectedTopFrameRegExp)); + expect(line2).toEqual(expect.stringMatching(expected2ndLineRegExp)); }); it('should slice according to end-frame arg', () => { - const _expectedTopLineRegExp = expected2ndLineRegExp; - const stackdump = callStackDumpFromTwoWrapperFn(1); - expect(stackdump).toEqual(expect.stringMatching(_expectedTopLineRegExp)); + const [,line1] = callStackDumpFromTwoWrapperFn(1).split('\n'); + expect(line1).toEqual(expect.stringMatching(expected2ndLineRegExp)); }); }); diff --git a/detox/src/utils/errorUtils.test.js b/detox/src/utils/errorUtils.test.js index f562dc5007..ad4197e35f 100644 --- a/detox/src/utils/errorUtils.test.js +++ b/detox/src/utils/errorUtils.test.js @@ -6,10 +6,14 @@ describe('sliceErrorStack(error, fromIndex)', () => { it('should clean up error stack by N first lines containing at:', () => { function innerFunction() { throw new Error('Source Error'); } function outerFunction() { innerFunction(); } + function attemptFunction() { + try { outerFunction(); } catch (e) { console.error('err', e); return e; } + } + const slicer = at => (_line) => --at < 0; - const error0 = errorUtils.filterErrorStack(_.attempt(outerFunction), slicer(0)); - const error2 = errorUtils.filterErrorStack(_.attempt(outerFunction), slicer(1)); - const error3 = errorUtils.filterErrorStack(_.attempt(outerFunction), slicer(2)); + const error0 = errorUtils.filterErrorStack(attemptFunction(), slicer(1)); + const error2 = errorUtils.filterErrorStack(attemptFunction(), slicer(2)); + const error3 = errorUtils.filterErrorStack(attemptFunction(), slicer(3)); expect(error0.stack).toMatch(/at innerFunction/); expect(error0.stack).toMatch(/at outerFunction/); expect(error2.stack).not.toMatch(/at innerFunction/); diff --git a/docs/Guide.Jest.md b/docs/Guide.Jest.md index 258998b214..a661f588fe 100644 --- a/docs/Guide.Jest.md +++ b/docs/Guide.Jest.md @@ -17,14 +17,12 @@ As already mentioned in the [Getting Started](Introduction.GettingStarted.md#set By the way, Jest itself — much like Detox, also does not effectively run any tests. Instead, it is more of a dispatcher and orchestrator of multiple instances of a delegated runner capable of running in parallel. For more info, refer to [this video](https://youtu.be/3YDiloj8_d0?t=2127) (source: [Jest architecture](https://jestjs.io/docs/en/architecture)). -For its part, Detox supports only one Jest’s concrete runner, which is [`jest-circus`](https://www.npmjs.com/package/jest-circus) ([ships by default with Jest since 27.0.0](https://jestjs.io/blog/2021/05/25/jest-27)). The former runner, `jest-jasmine2`, is deprecated due to specific bugs in the past, and architectural limitations at present. - ### Installation **Disclaimer:** 1. Here we focus on installing Detox on _new projects_. If you’re migrating a project with an existing Detox installation, please apply some common sense while using this guide. -1. These instructions are relevant for `jest@^27.0.0` (and `jest@^26.0.1 + jest-circus@^26.0.1`). They should likely work for the newer `jest` versions too, but for **the older ones** (25.x, 24.x) — **they will not, due to blocking issues.** +1. These instructions are relevant for `jest@^27.2.5` and `jest@28.x.x`. They should likely work for the newer `jest` versions too, but for **the older ones** (26.x, 25.x) — **they will not, due to blocking issues.** #### 1. Install Jest @@ -38,7 +36,6 @@ npm install -D "jest@>=27.2.5" **NOTE:** The command will install the _latest Jest version_. However, `@>=27.2.5` addendum is recommended just to be on the safe side in a common scenario, when a `package-lock.json` generated by an official React Native project template limits Jest version to a very old `26.x`, maybe due to some optimization mechanism. -Generally we recommend not to stay on outdated Jest versions for too long, e.g. `jest@27.2.5` will be the minimal version supported by Detox 20. #### 2. Set up Test-code Scaffolds diff --git a/examples/demo-react-native-jest/package.json b/examples/demo-react-native-jest/package.json index 5cdf909cc2..14e43dc296 100644 --- a/examples/demo-react-native-jest/package.json +++ b/examples/demo-react-native-jest/package.json @@ -14,7 +14,7 @@ "detox": "^19.6.8", "jest": "^28.0.0", "sanitize-filename": "^1.6.1", - "ts-jest": "^27.0.0", + "ts-jest": "^28.0.0", "typescript": "^4.1.3" }, "dependencies": {