diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 6c6b1e1..a4a053f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -16,7 +16,7 @@ jobs: - uses: styfle/cancel-workflow-action@0.9.1 with: all_but_latest: true - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 1 - name: Install Dependencies @@ -34,10 +34,10 @@ jobs: name: Deploy to GitHub Pages runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 16.x + node-version: 18.x cache: yarn - name: Install dependencies diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index a7442a6..b025eb7 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -17,16 +17,16 @@ jobs: - uses: styfle/cancel-workflow-action@0.9.1 with: all_but_latest: true - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 18 - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Yarn Cache id: yarn-cache with: @@ -53,7 +53,7 @@ jobs: repo-token: '${{ secrets.GITHUB_TOKEN }}' report-json: 'eslint-report.json' - name: Upload ESLint report - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: eslint-report.json path: eslint-report.json @@ -66,16 +66,16 @@ jobs: - uses: styfle/cancel-workflow-action@0.9.1 with: all_but_latest: true - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 1 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 18 - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Yarn Cache id: yarn-cache with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 55a32d3..f3106cf 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,12 +10,12 @@ jobs: timeout-minutes: 5 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 18 - name: Yarn Install uses: nick-invision/retry@v1 with: diff --git a/.github/workflows/tests_e2e_android.yml b/.github/workflows/tests_e2e_android.yml index cc824d3..772f147 100644 --- a/.github/workflows/tests_e2e_android.yml +++ b/.github/workflows/tests_e2e_android.yml @@ -31,17 +31,17 @@ jobs: with: all_but_latest: true - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 50 # Set up tool versions - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: - node-version: '16' + node-version: '18' - name: Configure JDK 1.11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '11' @@ -54,7 +54,7 @@ jobs: echo "::set-output name=yarn-cache-dir::$(yarn cache dir)" echo "::set-output name=tempdir::$TMPDIR" - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Yarn Cache id: yarn-cache with: @@ -70,7 +70,7 @@ jobs: max_attempts: 3 command: DETOX_DISABLE_POSTINSTALL=1 yarn --no-audit --prefer-offline && cd example && yarn --no-audit --prefer-offline - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Gradle Cache with: path: ~/.gradle/caches @@ -191,7 +191,7 @@ jobs: shell: bash - name: Upload Emulator Log - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: always() with: name: adb_logs diff --git a/.github/workflows/tests_e2e_ios.yml b/.github/workflows/tests_e2e_ios.yml index c414c97..2fcaa85 100644 --- a/.github/workflows/tests_e2e_ios.yml +++ b/.github/workflows/tests_e2e_ios.yml @@ -31,15 +31,15 @@ jobs: all_but_latest: true # Set up tool versions - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 18 - uses: maxim-lobanov/setup-xcode@v1 with: xcode-version: latest-stable - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 50 @@ -51,7 +51,7 @@ jobs: echo "::set-output name=xcode-version::$(xcodebuild -version|tail -1|cut -f3 -d' ')" echo "::set-output name=yarn-cache-dir::$(yarn cache dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Yarn Cache id: yarn-cache with: @@ -59,7 +59,7 @@ jobs: key: ${{ runner.os }}-yarn-v1-${{ hashFiles('**/package.json') }} restore-keys: ${{ runner.os }}-yarn-v1 - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Detox Framework Cache id: detox-cache with: @@ -94,7 +94,7 @@ jobs: max_attempts: 3 command: gem update cocoapods xcodeproj - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Cache Pods id: pods-cache with: @@ -167,7 +167,7 @@ jobs: run: gzip -9 simulator.log - name: Upload Simulator Log - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: always() with: name: simulator_log diff --git a/.github/workflows/tests_jest.yml b/.github/workflows/tests_jest.yml index e945178..e79e21b 100644 --- a/.github/workflows/tests_jest.yml +++ b/.github/workflows/tests_jest.yml @@ -27,16 +27,16 @@ jobs: - uses: styfle/cancel-workflow-action@0.9.1 with: all_but_latest: true - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 50 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 18 - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v4 name: Yarn Cache id: yarn-cache with: diff --git a/android/progaurd-rules.pro b/android/progaurd-rules.pro index 8c38705..d360c16 100644 --- a/android/progaurd-rules.pro +++ b/android/progaurd-rules.pro @@ -1 +1,2 @@ -keep class com.amazon.device.ads.** { *; } +-keep class com.adversport.rnaps.** { *; } diff --git a/jest.setup.ts b/jest.setup.ts index cfe81bb..0611e53 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -1,17 +1,43 @@ -import * as ReactNative from 'react-native'; +// Jest setup for React Native library testing -jest.mock( - './node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter' -); - -jest.doMock('react-native', () => { - return Object.setPrototypeOf( - { - Platform: { - OS: 'android', - select: () => {}, - }, +// Mock only performance object to fix Jest + React Native conflict +if (!(global as any).performance) { + Object.defineProperty(global, 'performance', { + writable: true, + enumerable: true, + configurable: true, + value: { + now: () => Date.now(), + mark: () => {}, + measure: () => {}, }, - ReactNative - ); -}); + }); +} + +// Minimal React Native mock - let individual tests override as needed +// Create a shared event emitter instance for all tests +const listeners = new Map(); + +const mockEventEmitter = { + addListener: jest.fn((eventName: string, listener: any) => { + if (!listeners.has(eventName)) { + listeners.set(eventName, []); + } + listeners.get(eventName)!.push(listener); + return { remove: jest.fn() }; + }), + removeAllListeners: jest.fn(), + emit: jest.fn((eventName: string, payload: any) => { + const eventListeners = listeners.get(eventName) || []; + eventListeners.forEach((listener: any) => listener(payload)); + }), +}; + +jest.mock('react-native', () => ({ + Platform: { + OS: 'android', + select: jest.fn(), + }, + NativeEventEmitter: jest.fn(() => mockEventEmitter), + NativeModules: {}, +})); diff --git a/package.json b/package.json index 7fb0772..b49e175 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "main": "lib/commonjs/index", "module": "lib/module/index", "types": "lib/typescript/index.d.ts", - "react-native": "src/index", "source": "src/index", "files": [ "/android/", @@ -113,13 +112,30 @@ "registry": "https://registry.npmjs.org/" }, "jest": { - "preset": "react-native", + "testEnvironment": "node", "modulePathIgnorePatterns": [ "/Example/node_modules", "/lib/" ], "setupFiles": [ "./jest.setup.ts" + ], + "transform": { + "^.+\\.(js|jsx|ts|tsx)$": "ts-jest" + }, + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "json" + ], + "testMatch": [ + "**/__tests__/**/*.(ts|tsx|js)" + ], + "collectCoverageFrom": [ + "src/**/*.{ts,tsx}", + "!src/**/*.d.ts" ] }, "detox": { @@ -260,5 +276,16 @@ "name": "rnaps", "type": "modules", "jsSrcsDir": "./src/turbomodules" + }, + "react-native": { + "main": "src/index", + "android": { + "sourceDir": "./android/", + "packageImportPath": "import com.adversport.rnaps.RNAPSPackage;", + "packageInstance": "new RNAPSPackage()" + }, + "ios": { + "podspecPath": "./RNAmazonPublisherServices.podspec" + } } } diff --git a/src/types/AdNetwork.ts b/src/types/AdNetwork.ts index be76bf8..072cfbc 100644 --- a/src/types/AdNetwork.ts +++ b/src/types/AdNetwork.ts @@ -24,7 +24,7 @@ export enum AdNetwork { MAX = 'MAX', NIMBUS = 'NIMBUS', OTHER = 'OTHER', -}; +} export function isAdNetwork(value: any): value is AdNetwork { return Object.values(AdNetwork).includes(value); diff --git a/src/types/MRAIDPolicy.ts b/src/types/MRAIDPolicy.ts index 04fcfe1..22f507e 100644 --- a/src/types/MRAIDPolicy.ts +++ b/src/types/MRAIDPolicy.ts @@ -20,7 +20,7 @@ export enum MRAIDPolicy { NONE = 'NONE', DFP = 'DFP', CUSTOM = 'CUSTOM', -}; +} export function isMRAIDPolicy(value: any): value is MRAIDPolicy { return Object.values(MRAIDPolicy).includes(value);