From d4fc3648d5602b4082e2ca68835c2fa160c959d6 Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Wed, 25 Oct 2023 14:47:57 +0200 Subject: [PATCH] Run tests for each package in isolation for mocks --- package.json | 147 ++++++++-------- packages/codepush/package.json | 149 ++++++++-------- packages/core/package.json | 10 +- .../react-native-apollo-client/package.json | 7 +- packages/react-native-navigation/package.json | 152 +++++++++-------- .../react-native-session-replay/package.json | 7 +- .../__mocks__/react-native.ts | 21 +++ packages/react-native-webview/package.json | 7 +- .../react-native-webview/src/NativeDdSdk.ts | 2 +- packages/react-navigation/package.json | 159 +++++++++--------- 10 files changed, 354 insertions(+), 307 deletions(-) create mode 100644 packages/react-native-webview/__mocks__/react-native.ts diff --git a/package.json b/package.json index 947622859..85b04a50c 100644 --- a/package.json +++ b/package.json @@ -1,84 +1,69 @@ { - "name": "dd-sdk-reactnative", - "description": "A client-side React Native module to interact with Datadog", - "keywords": [ - "datadog", - "react-native", - "ios", - "android" - ], - "author": "Datadog (https://github.com/DataDog)", - "homepage": "https://github.com/DataDog/dd-sdk-reactnative#readme", - "repository": "https://github.com/DataDog/dd-sdk-reactnative", - "bugs": { - "url": "https://github.com/DataDog/dd-sdk-reactnative/issues" - }, - "license": "Apache-2.0", - "private": true, - "workspaces": { - "packages": [ - "packages/*", - "example", - "example-new-architecture" - ] - }, - "scripts": { - "prepare": "genversion --es6 --semi packages/core/src/version.ts && lerna run prepare", - "test": "genversion --es6 --semi packages/core/src/version.ts && jest", - "lint": "genversion --es6 --semi packages/core/src/version.ts && eslint .", - "example": "yarn --cwd example", - "postinstall": "./packages/react-navigation/fix-react-navigation-import-in-dependencies.sh" - }, - "devDependencies": { - "@babel/plugin-transform-runtime": "7.12.15", - "@testing-library/react-native": "7.0.2", - "@types/jest": "^29.2.1", - "@types/react": "^18.0.24", - "@types/react-native": "0.71.0", - "@types/react-test-renderer": "18.0.0", - "@typescript-eslint/eslint-plugin": "5.20.0", - "@typescript-eslint/parser": "5.20.0", - "dd-trace": "^3.3.1", - "eslint": "8.10.0", - "eslint-config-prettier": "6.0.0", - "eslint-plugin-arca": "0.15.0", - "eslint-plugin-import": "2.25.4", - "eslint-plugin-prettier": "4.0.0", - "eslint-plugin-react": "7.22.0", - "eslint-plugin-react-hooks": "4.3.0", - "eslint-plugin-react-native": "3.10.0", - "genversion": "3.0.2", - "jest": "29.2.1", - "lerna": "7.1.0", - "metro-react-native-babel-preset": "0.73.9", - "pod-install": "0.1.14", - "prettier": "2.2.0", - "react": "18.2.0", - "react-native": "0.71.10", - "react-native-builder-bob": "0.17.1", - "react-native-webview": "11.26.1", - "react-test-renderer": "18.1.0", - "typescript": "4.8.4" - }, - "jest": { - "preset": "react-native", - "moduleNameMapper": { - "@datadog/mobile-react-native": "/packages/core/src" - }, - "modulePathIgnorePatterns": [ - "/example/node_modules", - "/packages/.*/lib/" - ], - "setupFiles": [ - "./node_modules/react-native-gesture-handler/jestSetup.js", - "./jest.setup.js" + "name": "dd-sdk-reactnative", + "description": "A client-side React Native module to interact with Datadog", + "keywords": [ + "datadog", + "react-native", + "ios", + "android" ], - "testPathIgnorePatterns": [ - "/__utils__/" - ], - "transformIgnorePatterns": [ - "jest-runner" - ] - }, - "packageManager": "yarn@3.4.1" + "author": "Datadog (https://github.com/DataDog)", + "homepage": "https://github.com/DataDog/dd-sdk-reactnative#readme", + "repository": "https://github.com/DataDog/dd-sdk-reactnative", + "bugs": { + "url": "https://github.com/DataDog/dd-sdk-reactnative/issues" + }, + "license": "Apache-2.0", + "private": true, + "workspaces": { + "packages": [ + "packages/*", + "example", + "example-new-architecture" + ] + }, + "scripts": { + "prepare": "genversion --es6 --semi packages/core/src/version.ts && lerna run prepare", + "test": "genversion --es6 --semi packages/core/src/version.ts && jest", + "lint": "genversion --es6 --semi packages/core/src/version.ts && eslint .", + "example": "yarn --cwd example", + "postinstall": "./packages/react-navigation/fix-react-navigation-import-in-dependencies.sh" + }, + "devDependencies": { + "@babel/plugin-transform-runtime": "7.12.15", + "@testing-library/react-native": "7.0.2", + "@types/jest": "^29.2.1", + "@types/react": "^18.0.24", + "@types/react-native": "0.71.0", + "@types/react-test-renderer": "18.0.0", + "@typescript-eslint/eslint-plugin": "5.20.0", + "@typescript-eslint/parser": "5.20.0", + "dd-trace": "^3.3.1", + "eslint": "8.10.0", + "eslint-config-prettier": "6.0.0", + "eslint-plugin-arca": "0.15.0", + "eslint-plugin-import": "2.25.4", + "eslint-plugin-prettier": "4.0.0", + "eslint-plugin-react": "7.22.0", + "eslint-plugin-react-hooks": "4.3.0", + "eslint-plugin-react-native": "3.10.0", + "genversion": "3.0.2", + "jest": "29.2.1", + "lerna": "7.1.0", + "metro-react-native-babel-preset": "0.73.9", + "pod-install": "0.1.14", + "prettier": "2.2.0", + "react": "18.2.0", + "react-native": "0.71.10", + "react-native-builder-bob": "0.17.1", + "react-native-webview": "11.26.1", + "react-test-renderer": "18.1.0", + "typescript": "4.8.4" + }, + "jest": { + "projects": [ + "/packages/*" + ] + }, + "packageManager": "yarn@3.4.1" } diff --git a/packages/codepush/package.json b/packages/codepush/package.json index 8cdd13d5c..a36f7c165 100644 --- a/packages/codepush/package.json +++ b/packages/codepush/package.json @@ -1,76 +1,81 @@ { - "name": "@datadog/mobile-react-native-code-push", - "version": "1.8.5", - "description": "A client-side React Native module to interact with Appcenter Codepush and Datadog", - "keywords": [ - "datadog", - "react-native", - "ios", - "android", - "codepush", - "appcenter" - ], - "author": "Datadog (https://github.com/DataDog)", - "homepage": "https://github.com/DataDog/dd-sdk-reactnative#readme", - "repository": { - "url": "https://github.com/DataDog/dd-sdk-reactnative", - "directory": "packages/codepush" - }, - "bugs": { - "url": "https://github.com/DataDog/dd-sdk-reactnative/issues" - }, - "license": "Apache-2.0", - "main": "lib/commonjs/index", - "files": [ - "src/**", - "lib/**" - ], - "types": "lib/typescript/codepush/src/index.d.ts", - "react-native": "src/index", - "source": "src/index", - "module": "lib/module/index", - "publishConfig": { - "access": "public" - }, - "scripts": { - "test": "jest", - "lint": "eslint .", - "prepare": "rm -rf lib && yarn bob build" - }, - "devDependencies": { - "@datadog/mobile-react-native": "^1.8.5", - "@testing-library/react-native": "7.0.2", - "react-native-builder-bob": "0.17.1", - "react-native-code-push": "7.0.5" - }, - "peerDependencies": { - "@datadog/mobile-react-native": "^1.0.0-beta4", - "react": ">=16.13.1", - "react-native": ">=0.63.4 <1.0", - "react-native-code-push": ">=2.0.0" - }, - "jest": { - "preset": "react-native", - "modulePathIgnorePatterns": [ - "/lib/" + "name": "@datadog/mobile-react-native-code-push", + "version": "1.8.5", + "description": "A client-side React Native module to interact with Appcenter Codepush and Datadog", + "keywords": [ + "datadog", + "react-native", + "ios", + "android", + "codepush", + "appcenter" ], - "testPathIgnorePatterns": [ - "/__utils__/" + "author": "Datadog (https://github.com/DataDog)", + "homepage": "https://github.com/DataDog/dd-sdk-reactnative#readme", + "repository": { + "url": "https://github.com/DataDog/dd-sdk-reactnative", + "directory": "packages/codepush" + }, + "bugs": { + "url": "https://github.com/DataDog/dd-sdk-reactnative/issues" + }, + "license": "Apache-2.0", + "main": "lib/commonjs/index", + "files": [ + "src/**", + "lib/**" ], - "transformIgnorePatterns": [] - }, - "react-native-builder-bob": { - "source": "src", - "output": "lib", - "targets": [ - "commonjs", - "module", - [ - "typescript", - { - "tsc": "./../../node_modules/.bin/tsc" - } - ] - ] - } + "types": "lib/typescript/codepush/src/index.d.ts", + "react-native": "src/index", + "source": "src/index", + "module": "lib/module/index", + "publishConfig": { + "access": "public" + }, + "scripts": { + "test": "jest", + "lint": "eslint .", + "prepare": "rm -rf lib && yarn bob build" + }, + "devDependencies": { + "@datadog/mobile-react-native": "^1.8.5", + "@testing-library/react-native": "7.0.2", + "react-native-builder-bob": "0.17.1", + "react-native-code-push": "7.0.5" + }, + "peerDependencies": { + "@datadog/mobile-react-native": "^1.0.0-beta4", + "react": ">=16.13.1", + "react-native": ">=0.63.4 <1.0", + "react-native-code-push": ">=2.0.0" + }, + "jest": { + "preset": "react-native", + "moduleNameMapper": { + "@datadog/mobile-react-native": "../core/src" + }, + "modulePathIgnorePatterns": [ + "/lib/" + ], + "testPathIgnorePatterns": [ + "/__utils__/" + ], + "transformIgnorePatterns": [ + "jest-runner" + ] + }, + "react-native-builder-bob": { + "source": "src", + "output": "lib", + "targets": [ + "commonjs", + "module", + [ + "typescript", + { + "tsc": "./../../node_modules/.bin/tsc" + } + ] + ] + } } diff --git a/packages/core/package.json b/packages/core/package.json index fa3b89ad6..33d6c1d84 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -55,14 +55,22 @@ }, "jest": { "preset": "react-native", + "moduleNameMapper": { + "@datadog/mobile-react-native": "../core/src" + }, "modulePathIgnorePatterns": [ "/lib/" ], + "testPathIgnorePatterns": [ + "/__utils__/" + ], "setupFiles": [ "./../../node_modules/react-native-gesture-handler/jestSetup.js", "./../../jest.setup.js" ], - "transformIgnorePatterns": [] + "transformIgnorePatterns": [ + "jest-runner" + ] }, "react-native-builder-bob": { "source": "src", diff --git a/packages/react-native-apollo-client/package.json b/packages/react-native-apollo-client/package.json index f12d7ef76..3fda94157 100644 --- a/packages/react-native-apollo-client/package.json +++ b/packages/react-native-apollo-client/package.json @@ -51,13 +51,18 @@ }, "jest": { "preset": "react-native", + "moduleNameMapper": { + "@datadog/mobile-react-native": "../core/src" + }, "modulePathIgnorePatterns": [ "/lib/" ], "testPathIgnorePatterns": [ "/__utils__/" ], - "transformIgnorePatterns": [] + "transformIgnorePatterns": [ + "jest-runner" + ] }, "react-native-builder-bob": { "source": "src", diff --git a/packages/react-native-navigation/package.json b/packages/react-native-navigation/package.json index e9b000ab4..ad35e6b26 100644 --- a/packages/react-native-navigation/package.json +++ b/packages/react-native-navigation/package.json @@ -1,76 +1,84 @@ { - "name": "@datadog/mobile-react-native-navigation", - "version": "1.8.5", - "description": "A client-side React Native module to interact with Datadog", - "keywords": [ - "datadog", - "react-native", - "ios", - "android" - ], - "author": "Datadog (https://github.com/DataDog)", - "homepage": "https://github.com/DataDog/dd-sdk-reactnative#readme", - "repository": { - "url": "https://github.com/DataDog/dd-sdk-reactnative", - "directory": "packages/react-native-navigation" - }, - "bugs": { - "url": "https://github.com/DataDog/dd-sdk-reactnative/issues" - }, - "license": "Apache-2.0", - "main": "lib/commonjs/index", - "files": [ - "src/**", - "lib/**" - ], - "types": "lib/typescript/react-native-navigation/src/index.d.ts", - "react-native": "src/index", - "source": "src/index", - "module": "lib/module/index", - "publishConfig": { - "access": "public" - }, - "scripts": { - "test": "jest", - "lint": "eslint .", - "prepare": "rm -rf lib && yarn bob build" - }, - "devDependencies": { - "@datadog/mobile-react-native": "^1.8.5", - "@testing-library/react-native": "7.0.2", - "react-native-builder-bob": "0.17.1", - "react-native-gesture-handler": "1.10.3", - "react-native-navigation": "7.31.1", - "remx": "3.x.x" - }, - "peerDependencies": { - "@datadog/mobile-react-native": "^1.0.0-beta4", - "react": ">=16.13.1", - "react-native": ">=0.63.4 <1.0", - "react-native-navigation": "^7.5.0" - }, - "jest": { - "preset": "react-native", - "modulePathIgnorePatterns": [ - "/lib/" + "name": "@datadog/mobile-react-native-navigation", + "version": "1.8.5", + "description": "A client-side React Native module to interact with Datadog", + "keywords": [ + "datadog", + "react-native", + "ios", + "android" ], - "setupFiles": [ - "./../../node_modules/react-native-gesture-handler/jestSetup.js" + "author": "Datadog (https://github.com/DataDog)", + "homepage": "https://github.com/DataDog/dd-sdk-reactnative#readme", + "repository": { + "url": "https://github.com/DataDog/dd-sdk-reactnative", + "directory": "packages/react-native-navigation" + }, + "bugs": { + "url": "https://github.com/DataDog/dd-sdk-reactnative/issues" + }, + "license": "Apache-2.0", + "main": "lib/commonjs/index", + "files": [ + "src/**", + "lib/**" ], - "transformIgnorePatterns": [] - }, - "react-native-builder-bob": { - "source": "src", - "output": "lib", - "targets": [ - "commonjs", - "module", - [ - "typescript", - { - "tsc": "./../../node_modules/.bin/tsc" - } - ] - ] - } + "types": "lib/typescript/react-native-navigation/src/index.d.ts", + "react-native": "src/index", + "source": "src/index", + "module": "lib/module/index", + "publishConfig": { + "access": "public" + }, + "scripts": { + "test": "jest", + "lint": "eslint .", + "prepare": "rm -rf lib && yarn bob build" + }, + "devDependencies": { + "@datadog/mobile-react-native": "^1.8.5", + "@testing-library/react-native": "7.0.2", + "react-native-builder-bob": "0.17.1", + "react-native-gesture-handler": "1.10.3", + "react-native-navigation": "7.31.1", + "remx": "3.x.x" + }, + "peerDependencies": { + "@datadog/mobile-react-native": "^1.0.0-beta4", + "react": ">=16.13.1", + "react-native": ">=0.63.4 <1.0", + "react-native-navigation": "^7.5.0" + }, + "jest": { + "preset": "react-native", + "moduleNameMapper": { + "@datadog/mobile-react-native": "../core/src" + }, + "modulePathIgnorePatterns": [ + "/lib/" + ], + "setupFiles": [ + "./../../node_modules/react-native-gesture-handler/jestSetup.js" + ], + "testPathIgnorePatterns": [ + "/__utils__/" + ], + "transformIgnorePatterns": [ + "jest-runner" + ] + }, + "react-native-builder-bob": { + "source": "src", + "output": "lib", + "targets": [ + "commonjs", + "module", + [ + "typescript", + { + "tsc": "./../../node_modules/.bin/tsc" + } + ] + ] + } } diff --git a/packages/react-native-session-replay/package.json b/packages/react-native-session-replay/package.json index b3c949714..2ff9b1b9c 100644 --- a/packages/react-native-session-replay/package.json +++ b/packages/react-native-session-replay/package.json @@ -52,6 +52,9 @@ }, "jest": { "preset": "react-native", + "moduleNameMapper": { + "@datadog/mobile-react-native": "../core/src" + }, "modulePathIgnorePatterns": [ "/lib/" ], @@ -59,7 +62,9 @@ "./../../node_modules/react-native-gesture-handler/jestSetup.js", "./../../jest.setup.js" ], - "transformIgnorePatterns": [] + "transformIgnorePatterns": [ + "jest-runner" + ] }, "react-native-builder-bob": { "source": "src", diff --git a/packages/react-native-webview/__mocks__/react-native.ts b/packages/react-native-webview/__mocks__/react-native.ts new file mode 100644 index 000000000..25a4ea88d --- /dev/null +++ b/packages/react-native-webview/__mocks__/react-native.ts @@ -0,0 +1,21 @@ +/* + * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. + * This product includes software developed at Datadog (https://www.datadoghq.com/). + * Copyright 2016-Present Datadog, Inc. + */ + +import type { PartialNativeDdSdkSpec } from '../src/NativeDdSdk'; + +// eslint-disable-next-line @typescript-eslint/no-var-requires +const actualRN = require('react-native'); + +actualRN.NativeModules.DdSdk = { + telemetryError: jest.fn().mockImplementation( + () => new Promise(resolve => resolve()) + ) as jest.MockedFunction, + consumeWebviewEvent: jest.fn().mockImplementation( + () => new Promise(resolve => resolve()) + ) as jest.MockedFunction +}; + +module.exports = actualRN; diff --git a/packages/react-native-webview/package.json b/packages/react-native-webview/package.json index e3fe41825..7858a567e 100644 --- a/packages/react-native-webview/package.json +++ b/packages/react-native-webview/package.json @@ -49,13 +49,18 @@ }, "jest": { "preset": "react-native", + "moduleNameMapper": { + "@datadog/mobile-react-native": "../core/src" + }, "modulePathIgnorePatterns": [ "/lib/" ], "testPathIgnorePatterns": [ "/__utils__/" ], - "transformIgnorePatterns": [] + "transformIgnorePatterns": [ + "jest-runner" + ] }, "react-native-builder-bob": { "source": "src", diff --git a/packages/react-native-webview/src/NativeDdSdk.ts b/packages/react-native-webview/src/NativeDdSdk.ts index 53ec26002..7ebc0e3b9 100644 --- a/packages/react-native-webview/src/NativeDdSdk.ts +++ b/packages/react-native-webview/src/NativeDdSdk.ts @@ -11,7 +11,7 @@ import { TurboModuleRegistry } from 'react-native'; * We have to redefine the spec for the Native SDK here to be able to use the new architecture. * We don't declare it in a spec file so we don't end up with a duplicate definition of the native module. */ -interface PartialNativeDdSdkSpec extends TurboModule { +export interface PartialNativeDdSdkSpec extends TurboModule { consumeWebviewEvent(message: string): Promise; telemetryError(message: string, stack: string, kind: string): Promise; } diff --git a/packages/react-navigation/package.json b/packages/react-navigation/package.json index 6c732623a..feec71004 100644 --- a/packages/react-navigation/package.json +++ b/packages/react-navigation/package.json @@ -1,81 +1,86 @@ { - "name": "@datadog/mobile-react-navigation", - "version": "1.8.5", - "description": "A client-side React Native module to interact with Datadog", - "keywords": [ - "datadog", - "react-native", - "ios", - "android" - ], - "author": "Datadog (https://github.com/DataDog)", - "homepage": "https://github.com/DataDog/dd-sdk-reactnative#readme", - "repository": { - "url": "https://github.com/DataDog/dd-sdk-reactnative", - "directory": "packages/react-navigation" - }, - "bugs": { - "url": "https://github.com/DataDog/dd-sdk-reactnative/issues" - }, - "license": "Apache-2.0", - "main": "lib/commonjs/index", - "files": [ - "src/**", - "lib/**" - ], - "types": "lib/typescript/react-navigation/src/index.d.ts", - "react-native": "src/index", - "source": "src/index", - "module": "lib/module/index", - "publishConfig": { - "access": "public" - }, - "scripts": { - "test": "jest", - "lint": "eslint .", - "prepare": "rm -rf lib && yarn bob build" - }, - "devDependencies": { - "@datadog/mobile-react-native": "^1.8.5", - "@react-navigation/native-v5": "npm:@react-navigation/native@5.9.8", - "@react-navigation/native-v6": "npm:@react-navigation/native@6.1.2", - "@react-navigation/stack-v5": "npm:@react-navigation/stack@5.14.2", - "@react-navigation/stack-v6": "npm:@react-navigation/stack@6.2.1", - "@testing-library/react-native": "7.0.2", - "react-native-builder-bob": "0.17.1", - "react-native-gesture-handler": "1.10.3", - "react-native-safe-area-context": "3.1.9" - }, - "peerDependencies": { - "@datadog/mobile-react-native": "^1.0.0-beta4", - "react": ">=16.13.1", - "react-native": ">=0.63.4 <1.0" - }, - "jest": { - "preset": "react-native", - "modulePathIgnorePatterns": [ - "/lib/" + "name": "@datadog/mobile-react-navigation", + "version": "1.8.5", + "description": "A client-side React Native module to interact with Datadog", + "keywords": [ + "datadog", + "react-native", + "ios", + "android" ], - "setupFiles": [ - "./../../node_modules/react-native-gesture-handler/jestSetup.js" + "author": "Datadog (https://github.com/DataDog)", + "homepage": "https://github.com/DataDog/dd-sdk-reactnative#readme", + "repository": { + "url": "https://github.com/DataDog/dd-sdk-reactnative", + "directory": "packages/react-navigation" + }, + "bugs": { + "url": "https://github.com/DataDog/dd-sdk-reactnative/issues" + }, + "license": "Apache-2.0", + "main": "lib/commonjs/index", + "files": [ + "src/**", + "lib/**" ], - "testPathIgnorePatterns": [ - "/__utils__/" - ], - "transformIgnorePatterns": [] - }, - "react-native-builder-bob": { - "source": "src", - "output": "lib", - "targets": [ - "commonjs", - "module", - [ - "typescript", - { - "tsc": "./../../node_modules/.bin/tsc" - } - ] - ] - } + "types": "lib/typescript/react-navigation/src/index.d.ts", + "react-native": "src/index", + "source": "src/index", + "module": "lib/module/index", + "publishConfig": { + "access": "public" + }, + "scripts": { + "test": "jest", + "lint": "eslint .", + "prepare": "rm -rf lib && yarn bob build" + }, + "devDependencies": { + "@datadog/mobile-react-native": "^1.8.5", + "@react-navigation/native-v5": "npm:@react-navigation/native@5.9.8", + "@react-navigation/native-v6": "npm:@react-navigation/native@6.1.2", + "@react-navigation/stack-v5": "npm:@react-navigation/stack@5.14.2", + "@react-navigation/stack-v6": "npm:@react-navigation/stack@6.2.1", + "@testing-library/react-native": "7.0.2", + "react-native-builder-bob": "0.17.1", + "react-native-gesture-handler": "1.10.3", + "react-native-safe-area-context": "3.1.9" + }, + "peerDependencies": { + "@datadog/mobile-react-native": "^1.0.0-beta4", + "react": ">=16.13.1", + "react-native": ">=0.63.4 <1.0" + }, + "jest": { + "preset": "react-native", + "moduleNameMapper": { + "@datadog/mobile-react-native": "../core/src" + }, + "modulePathIgnorePatterns": [ + "/lib/" + ], + "setupFiles": [ + "./../../node_modules/react-native-gesture-handler/jestSetup.js" + ], + "testPathIgnorePatterns": [ + "/__utils__/" + ], + "transformIgnorePatterns": [ + "jest-runner" + ] + }, + "react-native-builder-bob": { + "source": "src", + "output": "lib", + "targets": [ + "commonjs", + "module", + [ + "typescript", + { + "tsc": "./../../node_modules/.bin/tsc" + } + ] + ] + } }