Skip to content

Instantly share code, notes, and snippets.

View lorenzofox3's full-sized avatar

RENARD Laurent lorenzofox3

View GitHub Profile
@lorenzofox3
lorenzofox3 / ava.js
Created November 18, 2021 09:23
reporting-comparisonreporting-comparison
import test from 'ava';
import {Bar, Foo, monkeyPatched, objWithPrototype, simpleObj} from './tested.js';
test(`native custom type(date)`, (t) => {
t.deepEqual(
{prop: new Date('2222-01-01T00:00:00.000Z')},
{prop: '2222-01-01T00:00:00.000Z'}
);
});
@lorenzofox3
lorenzofox3 / package.json
Created May 10, 2021 13:51
ts-setup-example ts-setup-example
{
"name": "zora-coverage",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "ts-node sum.spec.ts",
"test:only": "RUN_ONLY=true ts-node sum.spec.ts",
"test:coverage": "c8 --exclude to-be-excluded.ts ts-node sum.spec.ts",
"dev": "nodemon sum.spec.ts"
@lorenzofox3
lorenzofox3 / api.js
Created April 11, 2021 14:21
separation-of-concern
import {createService} from './movies-service.js';
export default async (instance) => {
const {Movie} = instance; // mongoose model injected
instance.register(async (instance) => {
// we overwrite for the scope by our service instead
instance.decorate('Movie', createService({model: Movie}));
instance.register(routesPlugin);
});
}
@lorenzofox3
lorenzofox3 / package.json
Last active September 28, 2020 09:23
typescript example with ptatypescript example with pta
{
"name": "pta-ts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "ts-node ./node_modules/.bin/pta ./test.ts"
},
"author": "",
"license": "ISC",
@lorenzofox3
lorenzofox3 / memoize-test.js
Created June 23, 2020 10:41
check whether lodash memoize works on async function
const {test} = require(`zora`);
const memoize = require(`lodash/memoize.js`);
let callCount = 0;
const wait = (time = 200) => new Promise((resolve) => {
setTimeout(() => resolve(), time);
});
const fetchRemoteResource = memoize(async () => {
@lorenzofox3
lorenzofox3 / .babelrc
Last active January 25, 2020 17:24
babel with coverage set up
{
"sourceMaps": 'inline',
"presets": [
"@babel/preset-react"
]
}
@lorenzofox3
lorenzofox3 / reporter.js
Created October 29, 2019 13:59
a small zora like test runner for nodejs
module.exports = testResult => {
const isFailed = testResult.pass === false;
console.log(`${!isFailed ? 'ok' : 'no ok'} - ${testResult.description}`);
if (testResult.error) {
console.log(testResult.error.stack);
if (testResult.error.operator) {
console.log(`operator: ${testResult.error.operator}`);
}
if (testResult.error.expected) {
console.log(`expected: \n ${JSON.stringify(testResult.error.expected, null, 4)}`);
@lorenzofox3
lorenzofox3 / bin.js
Last active October 15, 2019 22:51
nodejs test runner for zora
#!/usr/bin/env node
const path = require('path');
const {Console} = require('console');
const globby = require('globby');
const zora = require('zora');
const TSR = require('tap-mocha-reporter');
const {createHarness, mochaTapLike} = zora;
const DEFAULT_PATH = ['*.spec.js', './test/*.js'];
@lorenzofox3
lorenzofox3 / index.js
Created October 11, 2019 22:26
test runner with `only` feature
import {report} from './tester.js';
report();
@lorenzofox3
lorenzofox3 / package.json
Last active January 24, 2020 11:36
typescript setup example
{
"name": "typescript-setup",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile": "tsc",
"test": "node -r esm ./spec.js",
"dev": "npm run compile -- -w"
},