This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+9
View File
@@ -0,0 +1,9 @@
# The MIT License
Copyright 2022 Harminder Virk, contributors
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.
+71
View File
@@ -0,0 +1,71 @@
# @japa/assert
> Assertion library built on top of Chai.assert
[![github-actions-image]][github-actions-url] [![npm-image]][npm-url] [![license-image]][license-url] [![typescript-image]][typescript-url]
An assertion library built on top of [Chai.assert](https://www.chaijs.com/guide/styles/#assert) with small tweaks and additional features like assertion planning.
#### [Complete API documentation](https://japa.dev/docs/plugins/assert)
## Installation
Install the package from the npm registry as follows:
```sh
npm i @japa/assert
yarn add @japa/assert
```
## Usage
You can use the assertion package with the `@japa/runner` as follows.
```ts
import { assert } from '@japa/assert'
import { configure } from '@japa/runner'
configure({
plugins: [assert()]
})
```
Once done, you will be able to access the `assert` property on the test context.
```ts
test('test title', ({ assert }) => {
assert.deepEqual({ id: 1 }, { id: 1})
})
```
## Register open API schemas
You can register open API schema and then assert HTTP responses against.
```ts
configure({
plugins: [assert({
openApi: {
schemas: [join(__dirname, '..', 'api-spec.json')]
}
})]
})
```
Validate response as follows.
```ts
test('get users', ({ assert }) => {
const response = await supertest(baseUrl).get('/users')
assert.isValidApiResponse(response)
})
```
[github-actions-url]: https://github.com/japa/assert/actions/workflows/test.yml
[github-actions-image]: https://img.shields.io/github/actions/workflow/status/japa/assert/test.yml?style=for-the-badge "github-actions"
[npm-image]: https://img.shields.io/npm/v/@japa/assert.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/@japa/assert "npm"
[license-image]: https://img.shields.io/npm/l/@japa/assert?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md "license"
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[typescript-url]: "typescript"
+14
View File
@@ -0,0 +1,14 @@
import type { PluginFn } from '@japa/runner';
import type { PluginConfig } from './src/types';
import { Assert } from './src/assert/main';
/**
* Plugin for "@japa/runner"
*/
export declare function assert(options?: PluginConfig): PluginFn;
export * from './src/types';
export { Assert };
declare module '@japa/runner' {
interface TestContext {
assert: Assert;
}
}
+48
View File
@@ -0,0 +1,48 @@
"use strict";
/*
* @japa/assert
*
* (c) Japa.dev
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Assert = exports.assert = void 0;
const main_1 = require("./src/assert/main");
Object.defineProperty(exports, "Assert", { enumerable: true, get: function () { return main_1.Assert; } });
/**
* Plugin for "@japa/runner"
*/
function assert(options) {
if (options?.openApi) {
main_1.Assert.registerApiSpecs(options.openApi.schemas, {
exportCoverage: options.openApi.exportCoverage,
reportCoverage: options.openApi.reportCoverage,
});
}
return function (_, __, { TestContext, Test }) {
TestContext.getter('assert', () => new main_1.Assert(), true);
Test.dispose(function (test, hasError) {
if (!hasError) {
test.context.assert.assertions.validate();
}
});
};
}
exports.assert = assert;
__exportStar(require("./src/types"), exports);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
/**
* Copy of https://github.com/debitoor/chai-subset/blob/master/lib/chai-subset.js
*
* The package is not maintained anymore, hence it makes more sense
* to own the small piece of code and evolve it as required.
*/
export declare function subsetCompare(expected: any, actual: any): any;
+71
View File
@@ -0,0 +1,71 @@
"use strict";
/*
* @japa/assert
*
* (c) Japa.dev
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.subsetCompare = void 0;
/**
* Copy of https://github.com/debitoor/chai-subset/blob/master/lib/chai-subset.js
*
* The package is not maintained anymore, hence it makes more sense
* to own the small piece of code and evolve it as required.
*/
function subsetCompare(expected, actual) {
if (expected === actual) {
return true;
}
if (typeof actual !== typeof expected) {
return false;
}
if (typeof expected !== 'object' || expected === null) {
return expected === actual;
}
if (!!expected && !actual) {
return false;
}
/**
* Handling arrays
*/
if (Array.isArray(expected)) {
if (typeof actual.length !== 'number') {
return false;
}
const aa = Array.prototype.slice.call(actual);
return expected.every(function (exp) {
return aa.some(function (act) {
return subsetCompare(exp, act);
});
});
}
/**
* Handling date instances
*/
if (expected instanceof Date) {
if (actual instanceof Date) {
return expected.getTime() === actual.getTime();
}
else {
return false;
}
}
/**
* Handling objects
*/
return Object.keys(expected).every(function (key) {
const eo = expected[key];
const ao = actual[key];
if (typeof eo === 'object' && eo !== null && ao !== null) {
return subsetCompare(eo, ao);
}
if (typeof eo === 'function') {
return eo(ao);
}
return ao === eo;
});
}
exports.subsetCompare = subsetCompare;
+18
View File
@@ -0,0 +1,18 @@
import { assert } from 'chai';
/**
* Unnecessary similar methods have been removed
*/
export type ChaiAssert = {
[K in keyof typeof assert]: (typeof assert)[K];
};
/**
* Assert contract
*/
export type AssertContract = Omit<ChaiAssert, 'deepStrictEqual' | 'nestedInclude' | 'notNestedInclude' | 'deepNestedInclude' | 'notDeepNestedInclude' | 'ifError' | 'changes' | 'changesBy' | 'doesNotChange' | 'changesButNotBy' | 'increases' | 'increasesBy' | 'doesNotIncrease' | 'increasesButNotBy' | 'decreases' | 'decreasesBy' | 'doesNotDecrease' | 'doesNotDecreaseBy' | 'decreasesButNotBy' | 'extensible' | 'isExtensible' | 'notExtensible' | 'isNotExtensible' | 'deepProperty' | 'notDeepProperty' | 'nestedProperty' | 'nestedPropertyVal' | 'notNestedProperty' | 'notNestedPropertyVal' | 'deepNestedProperty' | 'notDeepNestedProperty' | 'deepNestedPropertyVal' | 'notDeepNestedPropertyVal' | 'hasAnyKeys' | 'hasAllKeys' | 'containsAllKeys' | 'doesNotHaveAnyKeys' | 'doesNotHaveAllKeys' | 'throw' | 'Throw' | 'doesNotThrow' | 'hasAnyDeepKeys' | 'hasAllDeepKeys' | 'containsAllDeepKeys' | 'doesNotHaveAnyDeepKeys' | 'doesNotHaveAllDeepKeys' | 'closeTo' | 'operator' | 'oneOf' | 'ownInclude' | 'notOwnInclude' | 'deepOwnInclude' | 'notDeepOwnInclude'>;
export type PluginConfig = {
openApi?: {
schemas: string[];
reportCoverage?: boolean;
exportCoverage?: boolean;
};
};
+10
View File
@@ -0,0 +1,10 @@
"use strict";
/*
* @japa/assert
*
* (c) Japa.dev
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });
+136
View File
@@ -0,0 +1,136 @@
{
"name": "@japa/assert",
"version": "1.4.1",
"description": "Assertion module for Japa",
"main": "build/index.js",
"files": [
"build/src",
"build/index.d.ts",
"build/index.js"
],
"exports": {
".": "./build/index.js"
},
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test": "node .bin/test.js",
"clean": "del build",
"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile",
"prepublishOnly": "npm run build",
"lint": "eslint . --ext=.ts",
"format": "prettier --write .",
"commit": "git-cz",
"release": "np --message=\"chore(release): %s\"",
"version": "npm run build",
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json japa/assert"
},
"keywords": [
"assert",
"chai",
"japa"
],
"author": "virk,japa",
"license": "MIT",
"peerDependencies": {
"@japa/runner": "^2.1.1"
},
"devDependencies": {
"@adonisjs/mrm-preset": "^5.0.3",
"@adonisjs/require-ts": "^2.0.13",
"@japa/core": "^7.3.1",
"@japa/runner": "^2.3.0",
"@types/luxon": "^3.2.0",
"@types/node": "^18.13.0",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"del-cli": "^5.0.0",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-adonis": "^2.1.1",
"eslint-plugin-prettier": "^4.2.1",
"github-label-sync": "^2.2.0",
"husky": "^8.0.3",
"japa": "^4.0.0",
"luxon": "^3.2.1",
"mrm": "^4.1.13",
"np": "^7.6.3",
"prettier": "^2.8.4",
"typescript": "^4.9.5"
},
"mrmConfig": {
"core": false,
"license": "MIT",
"services": [
"github-actions"
],
"minNodeVersion": "16.13.1",
"probotApps": [
"stale",
"lock"
],
"runGhActionsOnWindows": false
},
"eslintConfig": {
"extends": [
"plugin:adonis/typescriptPackage",
"prettier"
],
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
}
},
"eslintIgnore": [
"build"
],
"prettier": {
"trailingComma": "es5",
"semi": false,
"singleQuote": true,
"useTabs": false,
"quoteProps": "consistent",
"bracketSpacing": true,
"arrowParens": "always",
"printWidth": 100
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"np": {
"contents": ".",
"anyBranch": false
},
"dependencies": {
"@types/chai": "^4.3.4",
"api-contract-validator": "^2.2.8",
"chai": "^4.3.7",
"macroable": "^7.0.2"
},
"publishConfig": {
"access": "public",
"tag": "latest"
},
"types": "./build/index.d.ts",
"directories": {
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/japa/assert.git"
},
"bugs": {
"url": "https://github.com/japa/assert/issues"
},
"homepage": "https://github.com/japa/assert#readme"
}