Skip to content

camiha/node-boilerplate

Repository files navigation

node-boilerplate

my node project's boilerplate. support in-source testing.

using packages

package manager

commands

  • nr dev watch src/index.ts
  • nr test run vitest
  • nr test:watch run vitest with watch mode
  • nr test:coverage show test coverage
  • nr build create build file
  • nr preview exec build file

in-source testing sample

const sub =
    (x: number) =>
    (y: number): number =>
        x - y;

const div =
    (x: number) =>
    (y: number): number =>
        x / y;

const goodbye = () => {
    return {
        baz: 'a disruption and blinder',
        qux: 'mn..',
    };
};

if (import.meta.vitest) {
    const { assert, describe, it, expect } = import.meta.vitest;

    describe('calc', () => {
        it('sub', () => {
            expect(sub(2)(1)).eq(1);
        });

        it('div', () => {
            expect(div(2)(1)).eq(2);
        });

        it('goodbye', () => {
            const actual = goodbye();

            assert.deepEqual(actual, {
                baz: 'a disruption and blinder',
                qux: 'mn..',
            });
        });
    });
}