Skip to content

Commit

Permalink
chore(test): Use Mocha.js instead of Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion committed Mar 19, 2024
1 parent 095ee88 commit 09bb775
Show file tree
Hide file tree
Showing 14 changed files with 629 additions and 2,146 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"compile": "turbo compile",
"docs": "yarn workspace react-native-spotlight-tour docs",
"ios": "yarn workspace example ios",
"lint": "eslint .",
"lint": "eslint . --report-unused-disable-directives",
"release": "turbo release --concurrency=1",
"start": "turbo start",
"start:reset": "turbo start:reset",
Expand All @@ -27,16 +27,16 @@
"packageManager": "[email protected]",
"devDependencies": {
"@styled/typescript-styled-plugin": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"all-contributors-cli": "^6.26.1",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-better-styled-components": "^1.1.2",
"eslint-plugin-etc": "^2.0.3",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^48.2.1",
"eslint-plugin-react": "^7.34.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-sonarjs": "^0.24.0",
"turbo": "^1.12.5",
Expand Down
13 changes: 13 additions & 0 deletions package/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://json.schemastore.org/mocharc",
"extension": ["ts", "tsx"],
"recursive": true,
"require": [
"ts-node/register",
"react-native-testing-mocks/register",
"test/setup.ts",
"test/hooks.ts"
],
"slow": 500,
"spec": ["test/**/*.test.ts?(x)"]
}
6 changes: 0 additions & 6 deletions package/babel.config.js

This file was deleted.

19 changes: 0 additions & 19 deletions package/jest.config.ts

This file was deleted.

15 changes: 6 additions & 9 deletions package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"compile": "tsc",
"docs": "typedoc",
"release": "semantic-release",
"test": "jest"
"test": "NODE_ENV=test mocha"
},
"packageManager": "[email protected]",
"dependencies": {
Expand All @@ -46,26 +46,23 @@
},
"devDependencies": {
"@assertive-ts/core": "^2.1.0",
"@babel/core": "^7.24.0",
"@babel/preset-env": "^7.24.0",
"@react-native/babel-preset": "^0.73.21",
"@testing-library/react-native": "^12.4.3",
"@types/jest": "^29.5.12",
"@assertive-ts/sinon": "^1.0.0",
"@testing-library/react-native": "^12.4.4",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.28",
"@types/react-test-renderer": "^18.0.7",
"@types/sinon": "^17.0.3",
"babel-jest": "^29.7.0",
"expect-type": "^0.18.0",
"jest": "^29.7.0",
"mocha": "^10.3.0",
"react": "^18.2.0",
"react-is": "^18.2.0",
"react-native": "0.73.6",
"react-native-svg": "^15.1.0",
"react-native-testing-mocks": "^1.2.0",
"react-test-renderer": "^18.2.0",
"semantic-release": "^23.0.3",
"semantic-release-yarn": "^3.0.2",
"sinon": "^17.0.1",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typedoc": "^0.25.12",
"typedoc-plugin-markdown": "^3.17.1",
Expand Down
5 changes: 3 additions & 2 deletions package/test/helpers/TestTour.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { Button, Text, TouchableOpacity, View } from "react-native";
import Sinon from "sinon";

import { AttachStep, SpotlightTourProvider, TourStep, useSpotlightTour } from "../../src/main";

Expand Down Expand Up @@ -40,7 +41,7 @@ const TestComponent: React.FC = () => {
</AttachStep>

<AttachStep index={1}>
<Button onPress={jest.fn()} title="Test button" />
<Button onPress={Sinon.fake} title="Test button" />
</AttachStep>

<TouchableOpacity onPress={tourContext.start}>
Expand All @@ -57,7 +58,7 @@ const defaultSteps = [

export const TestScreen: React.FC<TestScreenProps> = ({ steps }) => {
return (
<SpotlightTourProvider steps={steps ?? defaultSteps}>
<SpotlightTourProvider nativeDriver={false} steps={steps ?? defaultSteps}>
<TestComponent />
</SpotlightTourProvider>
);
Expand Down
46 changes: 0 additions & 46 deletions package/test/helpers/nativeMocks.ts

This file was deleted.

16 changes: 16 additions & 0 deletions package/test/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable react-hooks/rules-of-hooks */
import Sinon from "sinon";

export function mochaHooks(): Mocha.RootHookObject {
return {
afterEach() {
Sinon.restore();
},
beforeEach() {
Sinon.useFakeTimers({
advanceTimeDelta: 0,
shouldAdvanceTime: true,
});
},
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "@assertive-ts/core";
import { fireEvent, render, waitFor } from "@testing-library/react-native";
import { render, userEvent, waitFor } from "@testing-library/react-native";
import React, { useEffect } from "react";
import { Text, View } from "react-native";
import Sinon from "sinon";
Expand Down Expand Up @@ -58,7 +58,7 @@ describe("[Integration] TourOverlay.component.test.tsx", () => {

await waitFor(() => getByText("Step 1"));

fireEvent.press(getByText("Next"));
await userEvent.press(getByText("Next"));

await waitFor(() => getByText("Step 2"));

Expand All @@ -76,13 +76,13 @@ describe("[Integration] TourOverlay.component.test.tsx", () => {

await waitFor(() => getByText("Step 1"));

fireEvent.press(getByText("Next"));
await userEvent.press(getByText("Next"));

await waitFor(() => getByText("Step 2"));

expect(queryByText("Step 1")).toBeNull();

fireEvent.press(getByText("Previous"));
await userEvent.press(getByText("Previous"));

await waitFor(() => getByText("Step 1"));

Expand All @@ -102,7 +102,7 @@ describe("[Integration] TourOverlay.component.test.tsx", () => {

const backdrop = await findByTestId("Spot Svg");

fireEvent.press(backdrop);
await userEvent.press(backdrop);

await waitFor(() => getByText("Step 2"));

Expand All @@ -122,7 +122,7 @@ describe("[Integration] TourOverlay.component.test.tsx", () => {

const backdrop = await findByTestId("Spot Svg");

fireEvent.press(backdrop);
await userEvent.press(backdrop);

expect(queryByText("Step 1")).toBeNull();
expect(queryByText("Step 2")).toBeNull();
Expand All @@ -148,13 +148,13 @@ describe("[Integration] TourOverlay.component.test.tsx", () => {

const backdrop = await findByTestId("Spot Svg");

fireEvent.press(backdrop);
await userEvent.press(backdrop);

await waitFor(() => getByText("Step 2"));

expect(queryByText("Step 1")).toBeNull();

fireEvent.press(backdrop);
await userEvent.press(backdrop);

expect(queryByText("Step 1")).toBeNull();
expect(queryByText("Step 2")).toBeNull();
Expand All @@ -176,7 +176,7 @@ describe("[Integration] TourOverlay.component.test.tsx", () => {

const backdrop = await findByTestId("Spot Svg");

fireEvent.press(backdrop);
await userEvent.press(backdrop);

Sinon.assert.calledOnceWithExactly(spy, {
current: 0,
Expand All @@ -201,7 +201,7 @@ describe("[Integration] TourOverlay.component.test.tsx", () => {

await waitFor(() => getByText("Step 1"));

fireEvent.press(getByText("Stop"));
await userEvent.press(getByText("Stop"));

Sinon.assert.calledOnceWithExactly(spy, {
index: 0,
Expand All @@ -222,11 +222,11 @@ describe("[Integration] TourOverlay.component.test.tsx", () => {

await waitFor(() => getByText("Step 1"));

fireEvent.press(getByText("Next"));
await userEvent.press(getByText("Next"));

await waitFor(() => getByText("Step 2"));

fireEvent.press(getByText("Stop"));
await userEvent.press(getByText("Stop"));

Sinon.assert.calledOnceWithExactly(spy, {
index: 1,
Expand All @@ -249,15 +249,15 @@ describe("[Integration] TourOverlay.component.test.tsx", () => {

await waitFor(() => getByText("Step 1"));

fireEvent.press(getByText("Next"));
await userEvent.press(getByText("Next"));

await waitFor(() => getByText("Step 2"));

fireEvent.press(getByText("Next"));
await userEvent.press(getByText("Next"));

await waitFor(() => getByText("Step 3"));

fireEvent.press(getByText("Stop"));
await userEvent.press(getByText("Stop"));

Sinon.assert.calledOnceWithExactly(spy, {
index: 2,
Expand Down
Loading

0 comments on commit 09bb775

Please sign in to comment.