Skip to content

Commit

Permalink
Merge pull request #233 from ngarbezza/release-6-1-0
Browse files Browse the repository at this point in the history
Release 6.1.0
  • Loading branch information
ngarbezza authored Jul 13, 2022
2 parents af05a68 + 5ecdc7d commit 1a970cf
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 102 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [12.x, 14.x, 16.x, 18.x]
steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Build NPM package, run lint analysis and tests
Expand All @@ -23,7 +23,10 @@ jobs:
env:
CI: true
- name: Code Climate Coverage Action
uses: paambaati/[email protected]
uses: paambaati/[email protected]
with:
coverageCommand: npm run coverage
debug: true
env:
CC_TEST_REPORTER_ID: 6ace5bc20f45a4d3b1d1bd56b37e2ed97c92776e402f4f687bb5ee50853cb51c
- name: SonarCloud Scan
Expand All @@ -33,7 +36,7 @@ jobs:
-Dsonar.projectKey=ngarbezza_testy
-Dsonar.organization=ngarbezza
-Dsonar.projectName=Testy
-Dsonar.projectVersion=6.0.0
-Dsonar.projectVersion=6.1.0
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
-Dsonar.coverage.exclusions=tests/**
env:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
Expand All @@ -19,8 +19,8 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
Expand Down
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Everything is released :tada:

## [6.1.0] - 2022-07-13

### Added

* [[feature] support for asynchronous tests](https://github.com/ngarbezza/testy/issues/106), thank you
[@JavierGelatti](https://github.com/JavierGelatti) for the [initial implementation](https://github.com/ngarbezza/testy/pull/82)!
Now we can use `async`/`await` in test definitions.

### Fixed

* [[bug] before() and after() argument is not validated](https://github.com/ngarbezza/testy/issues/227)

* [[bug] multiple before() or after() empty blocks can be added to a test suite](https://github.com/ngarbezza/testy/issues/202)

* [[bug] swallowed/not precise exception when before() or after() fails](https://github.com/ngarbezza/testy/issues/230)

### Other changes

* Updates to the dev tools: eslint, github actions, code climate
* Added [10Pines](https://10pines.com) as sponsor: thanks for the support!

## [6.0.0] - 2021-11-21

### Breaking changes
Expand Down Expand Up @@ -294,7 +315,8 @@ readable and extensible. It also includes a huge internal refactor to make the t

* Fix passed count at test runner level (no reported issue)

[Unreleased]: https://github.com/ngarbezza/testy/compare/v6.0.0...HEAD
[Unreleased]: https://github.com/ngarbezza/testy/compare/v6.1.0...HEAD
[6.1.0]: https://github.com/ngarbezza/testy/compare/v6.0.0...v6.1.0
[6.0.0]: https://github.com/ngarbezza/testy/compare/v5.1.0...v6.0.0
[5.1.0]: https://github.com/ngarbezza/testy/compare/v5.0.2...v5.1.0
[5.0.2]: https://github.com/ngarbezza/testy/compare/v5.0.1...v5.0.2
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,29 @@ definition of `before()` and `after()` per suite, and they always receive a func
});
```
* **Support for pending tests**: if a test has no body, it will be reported as `[WIP]` and it won't be considered a failure.
* **Support for asynchronous tests**: if the code you are testing has `async` logic, you can `await` inside the test
definition and make assertions later. You can also use it on `before()` and `after()` declarations. Example:

```javascript
const { suite, test, assert, before } = require('@pmoo/testy');

const promiseOne = async () => Promise.resolve(42);
const promiseTwo = async () => Promise.resolve(21);

suite('using async & await', () => {
let answerOne;

before(async () => {
answerOne = await promiseOne();
});

test('comparing results from promises', async () => {
const answerTwo = await promiseTwo();
assert.that(answerOne).isEqualTo(42);
assert.that(answerTwo).isEqualTo(21);
});
});
```
* **Fail-Fast mode**: if enabled, it stops execution in the first test that fails (or has an error). Remaining tests will be marked as skipped.
* **Run tests and suites in random order**: a good test suite does not depend on a particular order. Enabling this setting is a good way to ensure that.
* **Strict check for assertions**: if a test does not evaluate any assertion while it is executed, the result is considered an error. Basically, a test with no assertion is considered a "bad" test.
Expand Down
32 changes: 28 additions & 4 deletions README_es.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,34 @@ _suite_. `before()` y `after()` reciben una función como parámetro y pueden ut
});
});
```
* **Soporte para tests pendientes**: Un test que no tenga cuerpo, será reportado como pendiente (`[WIP]`) y no se considerará una falla.
* **Modo "fail-fast"**: Cuando está habilitado, se detiene apenas encuentra un test que falle o lance un error. Los tests restantes serán marcados como no ejecutados (_skipped_).
* **Ejecutar tests en orden aleatorio**: Una buena suite de tests no depende de un orden particular de tests para ejecutarse correctamentee. Activando esta configuración es una buena forma de asegurar eso.
* **Chequeo estricto de presencia de aserciones**: Si un test no evalúa ninguna aserción durante su ejecución, el resultado se considera un error. Básicamente, un test que no tiene aserciones es un "mal" test.
* **Soporte para tests pendientes**: un test que no tenga cuerpo, será reportado como pendiente (`[WIP]`) y no se considerará una falla.
* **Soporte para tests asíncronos**: si el código que estás testeando requiere de `async`, es posible hacer `await`
dentro de la definicion del test y luego escribir las aserciones. También es posible hacer llamados asincrónicos en
`before()` y `after()`. Ejemplo:

```javascript
const { suite, test, assert, before } = require('@pmoo/testy');

const promesaUno = async () => Promise.resolve(42);
const promesaDos = async () => Promise.resolve(21);

suite('usando async y await', () => {
let respuestaUno;

before(async () => {
respuestaUno = await promesaUno();
});

test('comparando resultados de promesas', async () => {
const respuestaDos = await promesaDos();
assert.that(respuestaUno).isEqualTo(42);
assert.that(respuestaDos).isEqualTo(21);
});
});
```
* **Modo "fail-fast"**: cuando está habilitado, se detiene apenas encuentra un test que falle o lance un error. Los tests restantes serán marcados como no ejecutados (_skipped_).
* **Ejecutar tests en orden aleatorio**: una buena suite de tests no depende de un orden particular de tests para ejecutarse correctamentee. Activando esta configuración es una buena forma de asegurar eso.
* **Chequeo estricto de presencia de aserciones**: si un test no evalúa ninguna aserción durante su ejecución, el resultado se considera un error. Básicamente, un test que no tiene aserciones es un "mal" test.
* **Explícitamente marcar un test como fallido o pendiente**: Ejemplos:

```javascript
Expand Down
36 changes: 18 additions & 18 deletions lib/equality_assertion_strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const EqualityAssertionStrategy = {
DefaultEquality,
];
},

evaluate(actual, expected, criteria) {
return this.availableStrategies()
.find(strategy => strategy.appliesTo(actual, expected, criteria))
Expand All @@ -24,11 +24,11 @@ const EqualityAssertionStrategy = {

const BothPartsUndefined = {
__proto__: EqualityAssertionStrategy,

appliesTo(actual, expected) {
return isUndefined(actual) && isUndefined(expected);
},

evaluate() {
return {
comparisonResult: undefined,
Expand All @@ -39,11 +39,11 @@ const BothPartsUndefined = {

const CustomFunction = {
__proto__: EqualityAssertionStrategy,
appliesTo(actual, expected, criteria) {

appliesTo(_actual, _expected, criteria) {
return isFunction(criteria);
},

evaluate(actual, expected, criteria) {
return {
comparisonResult: criteria(actual, expected),
Expand All @@ -54,30 +54,30 @@ const CustomFunction = {

const CustomPropertyName = {
__proto__: EqualityAssertionStrategy,
appliesTo(actual, expected, criteria) {

appliesTo(_actual, _expected, criteria) {
return isString(criteria);
},

evaluate(actual, expected, criteria) {
if (this._comparisonCanBeMade(actual, expected, criteria)) {
return this._compareUsingCustomCriteria(actual, expected, criteria);
} else {
return this._failWithCriteriaNotFoundMessage(criteria);
}
},

_comparisonCanBeMade(actual, expected, criteria) {
return respondsTo(actual, criteria) && respondsTo(expected, criteria);
},

_compareUsingCustomCriteria(actual, expected, criteria) {
return {
comparisonResult: actual[criteria](expected),
additionalFailureMessage: () => I18nMessage.empty(),
};
},

_failWithCriteriaNotFoundMessage(criteria) {
return {
comparisonResult: false,
Expand All @@ -88,11 +88,11 @@ const CustomPropertyName = {

const ObjectWithEqualsProperty = {
__proto__: EqualityAssertionStrategy,

appliesTo(actual, _expected) {
return respondsTo(actual, 'equals');
},

evaluate(actual, expected) {
return {
comparisonResult: actual.equals(expected),
Expand All @@ -103,11 +103,11 @@ const ObjectWithEqualsProperty = {

const ObjectWithCyclicReference = {
__proto__: EqualityAssertionStrategy,

appliesTo(actual, expected) {
return isCyclic(actual) || isCyclic(expected);
},

evaluate(_actual, _expected) {
return {
comparisonResult: false,
Expand All @@ -118,11 +118,11 @@ const ObjectWithCyclicReference = {

const DefaultEquality = {
__proto__: EqualityAssertionStrategy,

appliesTo(_actual, _expected) {
return true;
},

evaluate(actual, expected) {
return {
comparisonResult: deepStrictEqual(actual, expected),
Expand Down
2 changes: 1 addition & 1 deletion lib/test_result.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TestResult {
}

class SkippedTest extends TestResult {
static canHandle(test, context) {
static canHandle(_test, context) {
return context.failFastMode.hasFailed();
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pmoo/testy",
"version": "6.0.0",
"version": "6.1.0",
"description": "A minimal testing framework, for educational purposes.",
"homepage": "https://ngarbezza.github.io/testy/",
"repository": {
Expand Down
Loading

0 comments on commit 1a970cf

Please sign in to comment.