Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @godaddy/javascript
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 5
37 changes: 37 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x, 24.x]

steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run linter
run: npm run lint --if-present

- name: Build
run: npm run build --if-present

- name: Run tests
run: npm test
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
12 changes: 12 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { defineConfig } = require('eslint/config');

const GDConfig = import('eslint-config-godaddy').then((mod) => mod.default);
Comment thread
rmarkins-godaddy marked this conversation as resolved.
Outdated

module.exports = defineConfig([
{
files: ['lib/**/*.js', 'test/**/*.js'],
Comment thread
rmarkins-godaddy marked this conversation as resolved.
extends: [
GDConfig,
]
}
]);
65 changes: 47 additions & 18 deletions lib/index.test.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,70 @@
'use strict';

const terminus = require('@godaddy/terminus');

const { expect } = require('chai');
const sinon = require('sinon');
const { describe, it, beforeEach, afterEach, mock } = require('node:test');
const assert = require('node:assert');

const createSlayTerminus = require('./');

describe('slay-terminus', () => {
let app;
let createTerminusStub;
let doneStub;
let createTerminusMock;
let doneMock;

beforeEach(() => {
app = sinon.mock();
app.servers = sinon.mock();
app.servers.http = sinon.mock();
app.after = sinon.stub().callsArgWith(1, {}, {}, sinon.spy());
createTerminusStub = sinon.stub(terminus, 'createTerminus');
doneStub = sinon.stub();
app = {
servers: {
http: {
on: mock.fn(),
}
},
after: mock.fn(async (event, callback) => {
try {
await callback({}, {}, () => {});
} catch (err) {
console.error('Error in app.after callback:', err);
}
})
};
createTerminusMock = mock.method(terminus, 'createTerminus');
doneMock = mock.fn();
});

it('creates a terminus preboot', () => {
const slayTerminus = createSlayTerminus({ foo: 'bar' });
expect(typeof slayTerminus).equals('function');
assert.strictEqual(typeof slayTerminus, 'function');
});

it('plugs terminus', () => {
const slayTerminus = createSlayTerminus({ foo: 'bar' });
slayTerminus(app, null, doneStub);
expect(app.after.calledWith('start')).equals(true);
expect(createTerminusStub.calledWith(app.servers.http, { foo: 'bar' }))
.equals(true);
expect(doneStub.called).equals(true);
slayTerminus(app, null, doneMock);
assert.strictEqual(app.after.mock.calls[0].arguments[0], 'start');
assert.strictEqual(createTerminusMock.mock.calls[0].arguments[0], app.servers.http);
assert.deepEqual(createTerminusMock.mock.calls[0].arguments[1], { foo: 'bar' });
Comment thread
rmarkins-godaddy marked this conversation as resolved.
assert.strictEqual(doneMock.mock.callCount(), 1);
Comment thread
rmarkins-godaddy marked this conversation as resolved.
Outdated
});

it('handles errors in app.after callback', async () => {
const testError = new Error('Test error');
app.after = mock.fn((event, callback) => {
callback({}, {}, () => {
throw testError;
});
});

const slayTerminus = createSlayTerminus({ foo: 'bar' });
await assert.rejects(
() => new Promise((resolve, reject) => {
slayTerminus(app, null, (err) => {
if (err) reject(err);
else resolve();
});
}),
testError
);
});

afterEach(() => {
sinon.restore();
mock.reset();
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling mock.reset() may not restore overridden methods or clear all mock state. Use mock.resetAll() and mock.restoreAll() (or the appropriate sandbox instance methods) to fully clean up mocks between tests.

Suggested change
mock.reset();
mock.resetAll();
mock.restoreAll();

Copilot uses AI. Check for mistakes.
});
});
Loading