Skip to content

Commit

Permalink
Merge pull request #7 from homer0/homer0_jsdoc
Browse files Browse the repository at this point in the history
Remove ESDoc and Jest-Ex
  • Loading branch information
homer0 committed Oct 10, 2020
2 parents 69f3b63 + c38db8c commit 398ee67
Show file tree
Hide file tree
Showing 11 changed files with 435 additions and 1,922 deletions.
9 changes: 0 additions & 9 deletions .esdoc.json

This file was deleted.

7 changes: 7 additions & 0 deletions .jestrc.js
@@ -0,0 +1,7 @@
module.exports = {
automock: true,
collectCoverage: true,
testPathIgnorePatterns: ['/node_modules/', '/utils/scripts/'],
unmockedModulePathPatterns: ['/node_modules/'],
testEnvironment: 'node',
};
7 changes: 0 additions & 7 deletions .jestrc.json

This file was deleted.

49 changes: 49 additions & 0 deletions .jsdoc.js
@@ -0,0 +1,49 @@
const packageJson = require('./package.json');

module.exports = {
source: {
include: ['./src'],
includePattern: '.js$',
},
plugins: [
'docdash/nativeTypesPlugin',
'plugins/markdown',
],
templates: {
cleverLinks: true,
default: {
includeDate: false,
},
},
opts: {
recurse: true,
destination: './docs',
readme: 'README.md',
template: 'node_modules/docdash',
},
docdash: {
title: packageJson.name,
meta: {
title: `${packageJson.name} docs`,
},
sectionOrder: [],
collapse: true,
refLinks: [
{
title: 'View the package on Yarn',
url: `https://yarnpkg.com/package/${packageJson.name}`,
type: 'yarn',
},
{
title: 'Go to the GitHub repository',
url: `https://github.com/${packageJson.repository}`,
type: 'github',
},
{
title: 'View the package on NPM',
url: `https://www.npmjs.com/package/${packageJson.name}`,
type: 'npm',
},
],
},
};
16 changes: 7 additions & 9 deletions package.json
Expand Up @@ -15,20 +15,15 @@
],
"dependencies": {},
"devDependencies": {
"@babel/preset-env": "7.11.5",
"@babel/core": "7.11.6",
"@babel/plugin-transform-runtime": "7.11.5",
"coveralls": "^3.1.0",
"esdoc": "^1.1.0",
"esdoc-standard-plugin": "^1.0.0",
"esdoc-node": "1.0.4",
"docdash": "homer0/docdash#semver:^2.1.0",
"eslint": "^7.11.0",
"eslint-plugin-homer0": "^5.0.2",
"husky": "^4.3.0",
"jasmine-expect": "^5.0.0",
"jest-ex": "^9.0.0",
"jest-cli": "^26.5.2",
"jest": "^26.4.2",
"jsdoc": "^3.6.6",
"leasot": "^11.3.0",
"lint-staged": "^10.4.0",
"wootils": "^4.2.0"
},
"engine-strict": true,
Expand All @@ -48,5 +43,8 @@
"pre-commit": "./utils/hooks/pre-commit",
"post-merge": "./utils/hooks/post-merge"
}
},
"lint-staged": {
"*.js": "eslint"
}
}
3 changes: 3 additions & 0 deletions src/index.js
Expand Up @@ -28,6 +28,7 @@
* @property {GetDependencies} getForEnhancement Given the list of all the obtained dependencies,
* it filters the ones needed for the enhancement
* class.
* @ignore
*/

/**
Expand Down Expand Up @@ -89,13 +90,15 @@ const getInjectData = (target = [], enhancement = []) => {
* class.
*
* @type {GetDependencies}
* @ignore
*/
getForTarget: (values) => values.slice(0, target.length),
/**
* Given the list of all the obtained dependencies, it filters the ones needed for the
* enhancement class.
*
* @type {GetDependencies}
* @ignore
*/
getForEnhancement: (values) => enhancement.map((dep) => (
values[enhancementPositions[dep]]
Expand Down
72 changes: 33 additions & 39 deletions tests/index.test.js
@@ -1,7 +1,5 @@
jest.unmock('/src/index');

require('jasmine-expect');
const enhance = require('/src/index');
jest.unmock('../src/index');
const enhance = require('../src/index');

describe('aurelia-class-enhancements', () => {
const delayExec = (fn) => new Promise((resolve) => {
Expand Down Expand Up @@ -135,7 +133,7 @@ describe('aurelia-class-enhancements', () => {
]);
});

it('should enhance a view model and call the methods from the enhancements (promise)', () => {
it('should enhance a view model and call the methods from the enhancements (async)', async () => {
// Given
const callQueue = [];
const baseId = 'base-vm';
Expand Down Expand Up @@ -172,24 +170,22 @@ describe('aurelia-class-enhancements', () => {
let sut = null;
// When
sut = new (enhance(EnhancementOne, EnhancementTwo)(Base))();
return sut.attached(arg)
.then(() => {
// Then
expect(callQueue).toEqual([
enhTwoId,
enhOneId,
baseId,
]);
expect(enhTwoAttached).toHaveBeenCalledTimes(1);
expect(enhTwoAttached).toHaveBeenCalledWith(arg);
expect(enhOneAttached).toHaveBeenCalledTimes(1);
expect(enhOneAttached).toHaveBeenCalledWith(arg);
expect(baseAttached).toHaveBeenCalledTimes(1);
expect(baseAttached).toHaveBeenCalledWith(arg);
});
await sut.attached(arg);
// Then
expect(callQueue).toEqual([
enhTwoId,
enhOneId,
baseId,
]);
expect(enhTwoAttached).toHaveBeenCalledTimes(1);
expect(enhTwoAttached).toHaveBeenCalledWith(arg);
expect(enhOneAttached).toHaveBeenCalledTimes(1);
expect(enhOneAttached).toHaveBeenCalledWith(arg);
expect(baseAttached).toHaveBeenCalledTimes(1);
expect(baseAttached).toHaveBeenCalledWith(arg);
});

it('should recive the "enhanced returns" on a lifecycle method (promise)', () => {
it('should recive the "enhanced returns" on a lifecycle method (async)', async () => {
// Given
const baseId = 'base-vm';
const baseAttached = jest.fn(() => baseId);
Expand All @@ -212,18 +208,18 @@ describe('aurelia-class-enhancements', () => {
}
const arg = 'hello world!';
let sut = null;
let result = null;
// When
sut = new (enhance(Enhancement)(Base))();
return sut.attached(arg).then((result) => {
// Then
expect(result).toBe(baseId);
expect(enhAttached).toHaveBeenCalledTimes(1);
expect(enhAttached).toHaveBeenCalledWith(arg);
expect(baseAttached).toHaveBeenCalledTimes(1);
expect(baseAttached).toHaveBeenCalledWith(arg);
expect(baseAttachedLifeCycle).toHaveBeenCalledTimes(1);
expect(baseAttachedLifeCycle).toHaveBeenCalledWith(enhId, expect.any(Enhancement));
});
result = await sut.attached(arg);
// Then
expect(result).toBe(baseId);
expect(enhAttached).toHaveBeenCalledTimes(1);
expect(enhAttached).toHaveBeenCalledWith(arg);
expect(baseAttached).toHaveBeenCalledTimes(1);
expect(baseAttached).toHaveBeenCalledWith(arg);
expect(baseAttachedLifeCycle).toHaveBeenCalledTimes(1);
expect(baseAttachedLifeCycle).toHaveBeenCalledWith(enhId, expect.any(Enhancement));
});

it('should enhance a view model and merge the enhancements dependencies', () => {
Expand Down Expand Up @@ -347,7 +343,7 @@ describe('aurelia-class-enhancements', () => {
expect(enhanceAttached).toHaveBeenCalledWith(arg);
});

it('should call a enhanced method even if its not defined on the base (promise)', () => {
it('should call a enhanced method even if its not defined on the base (async)', async () => {
// Given
class Base {}
const enhanceAttached = jest.fn();
Expand All @@ -360,13 +356,11 @@ describe('aurelia-class-enhancements', () => {
let sut = null;
// When
sut = new (enhance(Enhancement)(Base))();
return sut.attached(arg)
.then(() => {
// Then
expect(sut).toBeInstanceOf(Base);
expect(enhanceAttached).toHaveBeenCalledTimes(1);
expect(enhanceAttached).toHaveBeenCalledWith(arg);
});
await sut.attached(arg);
// Then
expect(sut).toBeInstanceOf(Base);
expect(enhanceAttached).toHaveBeenCalledTimes(1);
expect(enhanceAttached).toHaveBeenCalledWith(arg);
});

it('should call a base method even if its not defined on the enhancement', () => {
Expand Down
3 changes: 1 addition & 2 deletions utils/scripts/docs
@@ -1,3 +1,2 @@
#!/bin/bash -e
esdoc -c .esdoc.json
rm -rf docs/package.json
jsdoc -c .jsdoc.js
9 changes: 1 addition & 8 deletions utils/scripts/lint
@@ -1,9 +1,2 @@
#!/bin/bash -e
files=$(git status -s | grep -E '[AM?]+\s.+?\.(js|jsx)$' | cut -c3-)

# Prevent ESLint from running if there are no files
if [[ $files = "" ]] ; then
exit 0
fi

eslint ${files} --no-ignore;
lint-staged
22 changes: 2 additions & 20 deletions utils/scripts/test
@@ -1,20 +1,2 @@
#!/usr/bin/env node

const { JestExRunner } = require('jest-ex');
const { Logger } = require('wootils/node/logger');
const packageInfo = require('../../package.json');

const logger = new Logger(packageInfo.name);

new JestExRunner('./.jestrc.json', {
addTransformer: true,
addStubs: true,
cache: false,
runInParallel: false,
})
.run()
.then(() => logger.success('Yay! all the unit tests passed!'))
.catch(() => {
logger.error('Damn... something went wrong with the unit tests');
process.exit(1);
});
#!/bin/bash -e
jest -c ./.jestrc.js $@

0 comments on commit 398ee67

Please sign in to comment.