Skip to content

Commit

Permalink
Remove Chai
Browse files Browse the repository at this point in the history
Chai v5 is ESM-only which would be a really big migration. We're not
doing any complicated assertions in the tests here so I think it makes
sense to just switch to the built-in `assert` module. We get to drop a
dependency (just under 1MB) and I think assert is easier to understand
anyway.
  • Loading branch information
rowanmanning committed Oct 30, 2024
1 parent 10a40f3 commit f88e215
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 222 deletions.
133 changes: 0 additions & 133 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@dotcom-tool-kit/mocha": "^4.0.1",
"@dotcom-tool-kit/prettier": "^4.0.1",
"@financial-times/eslint-config-next": "^7.1.0",
"chai": "^4.3.6",
"dotcom-tool-kit": "^4.0.1",
"mocha": "^10.0.0",
"proxyquire": "^2.1.3",
Expand Down
6 changes: 3 additions & 3 deletions test/aggregate.check.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const expect = require('chai').expect;
const assert = require('node:assert/strict');
const config = require('./fixtures/config/aggregate').checks[2];
const AggregateCheck = require('../src/checks/').aggregate;

Expand Down Expand Up @@ -34,7 +34,7 @@ describe('Aggregate Check', function () {
MockHealthChecks.checks[1].ok = true;
check.start();
setTimeout(function () {
expect(check.getStatus().ok).to.be.true;
assert.equal(check.getStatus().ok, true);
done();
});
});
Expand All @@ -44,7 +44,7 @@ describe('Aggregate Check', function () {
MockHealthChecks.checks[1].ok = false;
check.start();
setTimeout(function () {
expect(check.getStatus().ok).to.be.false;
assert.equal(check.getStatus().ok, false);
done();
});
});
Expand Down
27 changes: 13 additions & 14 deletions test/cloudWatchAlarm.check.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const expect = require('chai').expect;
const assert = require('node:assert/strict');
const configFixture = require('./fixtures/config/cloudWatchAlarmFixture')
.checks[0];
const failedFixture = require('./fixtures/cloudWatchAlarmFailedResponse');
Expand Down Expand Up @@ -43,44 +43,43 @@ describe('CloudWatch Alarm Check', () => {
check.start();
await waitFor(10);
//
expect(cloudWatchSdkMock.CloudWatchClient.calledOnce).to.be.true;
expect(cloudWatchSdkMock.CloudWatchClient.calledWithNew()).to.be.true;
expect(cloudWatchSdkMock.DescribeAlarmsCommand.calledOnce).to.be.true;
expect(cloudWatchSdkMock.DescribeAlarmsCommand.calledWithNew()).to.be.true;
expect(cloudWatchClientMock.send.calledOnce).to.be.true;
assert.equal(cloudWatchSdkMock.CloudWatchClient.calledOnce, true);
assert.equal(cloudWatchSdkMock.CloudWatchClient.calledWithNew(), true);
assert.equal(cloudWatchSdkMock.DescribeAlarmsCommand.calledOnce, true);
assert.equal(cloudWatchSdkMock.DescribeAlarmsCommand.calledWithNew(), true);
assert.equal(cloudWatchClientMock.send.calledOnce, true);

const sendArgs = cloudWatchClientMock.send.lastCall.args[0];
expect(sendArgs).to.deep.equal(cloudWatchCommandMock);
assert.deepEqual(sendArgs, cloudWatchCommandMock);

const commandArgs =
cloudWatchSdkMock.DescribeAlarmsCommand.lastCall.args[0];
expect(commandArgs).to.have.property('AlarmNames');
expect(commandArgs.AlarmNames).to.be.an('Array');
expect(commandArgs.AlarmNames[0]).to.be.an('String');
expect(commandArgs.AlarmNames[0]).to.equal('test');
assert.ok(commandArgs.AlarmNames);
assert.ok(Array.isArray(commandArgs.AlarmNames));
assert.equal(commandArgs.AlarmNames[0], 'test');
});

it('Should pass if the current state of the given alarm is OK', async () => {
cloudWatchClientMock.send.returns(Promise.resolve(passedFixture));
check = new Check(configFixture);
check.start();
await waitFor(10);
expect(check.getStatus().ok).to.be.true;
assert.equal(check.getStatus().ok, true);
});

it('Should fail if the current state of the given alarm is ALARM', async () => {
cloudWatchClientMock.send.returns(Promise.resolve(failedFixture));
check = new Check(configFixture);
check.start();
await waitFor(10);
expect(check.getStatus().ok).to.be.false;
assert.equal(check.getStatus().ok, false);
});

it('Should fail if there is no data', async () => {
cloudWatchClientMock.send.returns(Promise.resolve(insufficentFixture));
check = new Check(configFixture);
check.start();
await waitFor(10);
expect(check.getStatus().ok).to.be.false;
assert.equal(check.getStatus().ok, false);
});
});
Loading

0 comments on commit f88e215

Please sign in to comment.