Skip to content

Commit

Permalink
feat(native): Plugin scaffold (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion authored Nov 5, 2024
1 parent 8d7ffba commit 4c59a4d
Show file tree
Hide file tree
Showing 21 changed files with 4,373 additions and 70 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"alwaysTryTypes": true,
"project": "./tsconfig.json"
}
},
"react": {
"version": "detect"
}
},
"parserOptions": {
Expand All @@ -22,7 +25,9 @@
"@typescript-eslint",
"eslint-plugin-import",
"eslint-plugin-jsdoc",
"eslint-plugin-react",
"etc",
"react-hooks",
"sonarjs"
],
"extends": [
Expand All @@ -31,6 +36,8 @@
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:etc/recommended",
"plugin:import/typescript",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:sonarjs/recommended"
],
"overrides": [{
Expand Down Expand Up @@ -176,6 +183,7 @@
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": ["error", { "excludeTags": ["example", "param", "returns"] }],
"jsdoc/tag-lines": ["error", "any", { "startLines": 1 }],
"jsx-quotes": "error",
"keyword-spacing": "error",
"linebreak-style": "error",
"max-classes-per-file": ["error", 1],
Expand Down Expand Up @@ -215,6 +223,22 @@
"quote-props": ["error", "as-needed"],
"radix": "error",
"rest-spread-spacing": "error",
"react/display-name": "off",
"react/hook-use-state": "error",
"react/jsx-boolean-value": ["error", "always"],
"react/jsx-closing-bracket-location": "error",
"react/jsx-curly-spacing": ["error", { "when": "never" }],
"react/jsx-equals-spacing": ["error", "never"],
"react/jsx-max-props-per-line": ["error", {
"maximum": 1,
"when": "multiline"
}],
"react/jsx-no-bind": "error",
"react/jsx-no-literals": "error",
"react/jsx-tag-spacing": "error",
"react/prop-types": "off",
"react/self-closing-comp": "error",
"react-hooks/rules-of-hooks": "error",
"semi-spacing": "error",
"sonarjs/cognitive-complexity": "off",
"sonarjs/no-duplicate-string": "off",
Expand Down
1 change: 1 addition & 0 deletions examples/mocha/test/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react-hooks/rules-of-hooks */
import { usePlugin } from "@assertive-ts/core";
import { SymbolPlugin } from "@examples/symbol-plugin";
import { RootHookObject } from "mocha";
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"eslint-plugin-etc": "^2.0.3",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^48.2.1",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-sonarjs": "^0.24.0",
"turbo": "^1.12.4",
"typescript": "^5.4.2"
Expand Down
6 changes: 3 additions & 3 deletions packages/dom/test/unit/lib/ElementAssertion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("[Unit] ElementAssertion.test.ts", () => {

context("and it is an indirect child", () => {
it("returns the assertion instance", async () => {
const { findByTestId } = render(<NestedElementsTestComponent/>);
const { findByTestId } = render(<NestedElementsTestComponent />);
const grandparent = await findByTestId("grandparent");
const child = await findByTestId("child");
const grandparentTest = new ElementAssertion(grandparent);
Expand All @@ -84,7 +84,7 @@ describe("[Unit] ElementAssertion.test.ts", () => {

context("and it is a deeply nested child", () => {
it("returns the assertion instance", async () => {
const { findByTestId } = render(<NestedElementsTestComponent/>);
const { findByTestId } = render(<NestedElementsTestComponent />);
const grandparent = await findByTestId("grandparent");
const deepChild = await findByTestId("deep-child");
const grandparentTest = new ElementAssertion(grandparent);
Expand All @@ -101,7 +101,7 @@ describe("[Unit] ElementAssertion.test.ts", () => {
context("when element is NOT contained in ancestor element", () => {
it("throws an assertion error", async () => {
const notChildElement = document.createElement("span");
const { findByTestId } = render(<NestedElementsTestComponent/>);
const { findByTestId } = render(<NestedElementsTestComponent />);
const grandparent = await findByTestId("grandparent");
const grandparentTest = new ElementAssertion(grandparent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export function NestedElementsTestComponent(): ReactElement {
<span>
<span>
<span>
<span data-testid="deep-child"></span>
<span data-testid="deep-child" />
</span>
</span>
</span>
</span>
</span>
<svg data-testid="svg-element"></svg>
<svg data-testid="svg-element" />
</span>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ReactElement } from "react";
export function SimpleTestComponent(): ReactElement {
return (
<div>
<button>click me</button>
<button>{"click me"}</button>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ReactElement } from "react";
export function WithAttributesTestComponent(): ReactElement {
return (
<button role="button" type="submit" className="btn primary" disabled={true}>
click me
{"click me"}
</button>
);
}
12 changes: 12 additions & 0 deletions packages/native/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$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"
],
"spec": ["test/**/*.test.*"]
}
16 changes: 16 additions & 0 deletions packages/native/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://json.schemastore.org/semantic-release",
"branches": ["main"],
"plugins": [
["@semantic-release/commit-analyzer", {
"releaseRules": [
{ "scope": "!all", "release": false },
{ "scope": "!native", "release": false }
]
}],
"@semantic-release/release-notes-generator",
"semantic-release-yarn",
"@semantic-release/github"
],
"tagFormat": "native/v${version}"
}
21 changes: 21 additions & 0 deletions packages/native/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Stack Builders Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions packages/native/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Assertive.ts Native

An Assertive.ts plugin that provides assertion Matchers for React Native elements.

## Requirements

- **@assertive-ts/core:** >=2.0.0

## Install

```sh
npm install --save-dev @assertive-ts/native
```

Or:

```sh
yarn add --dev @assertive-ts/native
```

## API Reference

You can find the full API reference [here](https://stackbuilders.github.io/assertive-ts/docs/native/build/) 📚

## Usage

// TODO: Add usage documentation and examples...

## License

MIT, see [the LICENSE file](https://github.com/stackbuilders/assertive-ts/blob/main/packages/native/LICENSE).

## Contributing

Do you want to contribute to this project? Please take a look at our [contributing guidelines](https://github.com/stackbuilders/assertive-ts/blob/main/docs/CONTRIBUTING.md) to know how you can help us build it.

---

<img src="https://www.stackbuilders.com/media/images/Sb-supports.original.png" alt="Stack Builders" width="50%" />

[Check out our libraries](https://github.com/stackbuilders/) | [Join our team](https://www.stackbuilders.com/join-us/)
82 changes: 82 additions & 0 deletions packages/native/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "@assertive-ts/native",
"version": "0.0.0",
"description": "Assertive.ts plugin for React Native assertions",
"repository": "[email protected]:stackbuilders/assertive-ts.git",
"homepage": "https://stackbuilders.github.io/assertive-ts/",
"author": "Stack Builders <[email protected]>",
"license": "MIT",
"keywords": [
"assertions",
"assertive-ts",
"testing",
"testing-tools",
"type-safety",
"typescript",
"plugin",
"react-native"
],
"main": "./dist/main.js",
"types": "./dist/main.d.ts",
"files": [
"dist/",
"src/"
],
"engines": {
"node": ">=18"
},
"scripts": {
"build": "tsc -p tsconfig.prod.json",
"check": "yarn compile && yarn test --forbid-only",
"compile": "tsc -p tsconfig.json",
"docs": "typedoc",
"release": "semantic-release",
"test": "NODE_ENV=test mocha"
},
"dependencies": {
"fast-deep-equal": "^3.1.3",
"tslib": "^2.6.2"
},
"devDependencies": {
"@assertive-ts/core": "workspace:^",
"@testing-library/react-native": "^12.4.4",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.19",
"@types/react": "^18.2.70",
"@types/react-test-renderer": "^18.0.7",
"@types/sinon": "^17.0.3",
"mocha": "^10.3.0",
"react": "^18.2.0",
"react-native": "^0.73.6",
"react-native-testing-mocks": "^1.2.0",
"react-test-renderer": "^18.2.0",
"semantic-release": "^23.0.2",
"semantic-release-yarn": "^3.0.2",
"sinon": "^17.0.1",
"ts-node": "^10.9.2",
"typedoc": "^0.25.8",
"typedoc-plugin-markdown": "^3.17.1",
"typedoc-plugin-merge-modules": "^5.1.0",
"typescript": "^5.4.2"
},
"peerDependencies": {
"@assertive-ts/core": ">=2.0.0",
"react": "*",
"react-native": "*"
},
"peerDependenciesMeta": {
"@assertive-ts/core": {
"optional": false
},
"react": {
"optional": false
},
"react-native": {
"optional": false
}
},
"publishConfig": {
"access": "public",
"provenance": true
}
}
Empty file.
Empty file added packages/native/src/main.ts
Empty file.
16 changes: 16 additions & 0 deletions packages/native/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,
});
},
};
}
11 changes: 11 additions & 0 deletions packages/native/test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { userEvent } from "@testing-library/react-native";
import Sinon from "sinon";

process.env.RNTL_SKIP_AUTO_DETECT_FAKE_TIMERS = "true";

const newUserEvent = userEvent.setup({
advanceTimers: delay => Sinon.clock.tickAsync(delay).then(),
delay: 0,
});

Object.assign(userEvent, newUserEvent);
3 changes: 3 additions & 0 deletions packages/native/test/unit/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe("[Unit] main.test.ts", () => {
// main tests here...
});
18 changes: 18 additions & 0 deletions packages/native/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"jsx": "react-jsx",
"outDir": "./build",
"typeRoots": [
"../../node_modules/@types/",
"./typings/"
]
},
"exclude": [
"build/*",
"dist/*"
],
"ts-node": {
"transpileOnly": true
}
}
11 changes: 11 additions & 0 deletions packages/native/tsconfig.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"incremental": false,
"outDir": "./dist"
},
"include": [
"src/**/*",
"typings/**/*"
]
}
Loading

0 comments on commit 4c59a4d

Please sign in to comment.