Skip to content

Commit

Permalink
Fixed package
Browse files Browse the repository at this point in the history
  • Loading branch information
gastonpereyra committed Sep 26, 2021
1 parent 3519012 commit 55203bd
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 30 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.0.1] - 2021-09-26
### Fixed
- Fixed Context Blocks

## [1.0.0] - 2021-09-25
- Added Function for Context
- Added Function for It
- Added Function for Handler
### Added
- Function for Context
- Function for It
- Function for Handler
12 changes: 6 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ module.exports = class VercelServerlessApiTests {

/* istanbul ignore next */
if(only)
context.only(contextTitle, this.contextFunction(tests, options));
context.only(contextTitle, () => this.contextFunction(tests, options));
else
context(contextTitle, this.contextFunction(tests, options));
context(contextTitle, () => this.contextFunction(tests, options));
}

/**
* The function for a Context Block
* @param {ItProperties[]} tests The list of tests
* @param {ContextOptions} options
*/
async contextFunction(tests, {
contextFunction(tests, {
before: optionsBefore,
after: optionsAfter,
beforeEach: optionsBeforerEach,
Expand Down Expand Up @@ -155,10 +155,10 @@ module.exports = class VercelServerlessApiTests {

/* istanbul ignore next */
if(itOnly)
it.only(description, this.itFunction(request, response, options));
it.only(description, async () => this.itFunction(request, response, options));

else
it(description, this.itFunction(request, response, options));
it(description, async () => this.itFunction(request, response, options));
}

/**
Expand All @@ -168,7 +168,7 @@ module.exports = class VercelServerlessApiTests {
* @param {Response} response
* @param {ItOptions} options
*/
async itFunction(request, response, { itBefore, itAfter }) {
async itFunction(request, response, { itBefore, itAfter } = {}) {

if(itBefore)
await itBefore(sinon);
Expand Down
2 changes: 1 addition & 1 deletion 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": "vercel-serverless-tests",
"version": "1.0.0",
"version": "1.0.1",
"description": "A Helper to make tests with vercel-serverless-api package",
"main": "lib/index.js",
"files": [
Expand Down
67 changes: 48 additions & 19 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ describe('Vercel Serverless Api Tests', () => {
let ApiTests;

beforeEach(() => {
sandbox.restore();
ApiTests = new VercelServerlessApiTests(apiHanlder);
});

afterEach(() => {
sandbox.restore();
});

it('Should skip tests and not called the it function', async () => {

sandbox.spy(ApiTests, 'itFunction');
Expand All @@ -140,26 +143,16 @@ describe('Vercel Serverless Api Tests', () => {
sandbox.assert.notCalled(ApiTests.itFunction);
});

it('Should execute test without any before or after options', async () => {

sandbox.spy(ApiTests, 'itFunction');
it('Should execute test without only', async () => {

ApiTests.itTest({
description: 'Should test',
request: { url: 'api/test' },
response: { status: 200 }
});

sandbox.assert.calledOnceWithExactly(ApiTests.itFunction,
{ url: 'api/test' },
{ status: 200 },
{}
);
});

it('Should execute test with before or after options', async () => {

sandbox.spy(ApiTests, 'itFunction');
it('Should execute test', async () => {

const testFunction = () => { return true; };

Expand All @@ -170,12 +163,48 @@ describe('Vercel Serverless Api Tests', () => {
before: testFunction,
after: testFunction
});
});
});

describe('It function', () => {

const apiHanlder = (...args) => handler(API, ...args);

let ApiTests;

beforeEach(() => {
ApiTests = new VercelServerlessApiTests(apiHanlder);
});

sandbox.assert.calledOnceWithExactly(ApiTests.itFunction,
{},
{},
{ itBefore: testFunction, itAfter: testFunction }
);
afterEach(() => {
sandbox.restore();
});

it('Should execute test without any before or after options', async () => {

sandbox.stub(ApiTests, 'testHandler');

await ApiTests.itFunction({ url: 'api/test' }, { status: 200 });

sandbox.assert.calledOnceWithExactly(ApiTests.testHandler, { url: 'api/test' }, { status: 200 });
});

it('Should execute test with before or after options', async () => {

const options = {
itBefore: () => true,
itAfter: () => true
};

sandbox.stub(ApiTests, 'testHandler');
sandbox.spy(options, 'itBefore');
sandbox.spy(options, 'itAfter');

await ApiTests.itFunction({ url: 'api/test/1' }, { status: 201 }, options);

sandbox.assert.calledOnceWithExactly(ApiTests.testHandler, { url: 'api/test/1' }, { status: 201 });
sandbox.assert.calledOnce(options.itBefore);
sandbox.assert.calledOnce(options.itAfter);
});
});

Expand Down Expand Up @@ -246,7 +275,7 @@ describe('Vercel Serverless Api Tests', () => {
beforeEach: () => {},
afterEach: () => {}
};
sandbox.stub(ApiTests, 'itTest');
sandbox.spy(ApiTests, 'itTest');

ApiTests.contextTest('When must execute test with beforeEach and afterEach', [
sampleTest,
Expand Down

0 comments on commit 55203bd

Please sign in to comment.