Skip to content

Commit

Permalink
use forked version of chai-as-promised for chai 5 compatibility + rem…
Browse files Browse the repository at this point in the history
…ove chai-immutable
  • Loading branch information
deniak committed Jan 17, 2024
1 parent a58e05a commit dfc85e3
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 43 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
},
"devDependencies": {
"chai": "5.0.0",
"chai-as-promised": "7.1.1",
"chai-immutable": "2.1.0",
"@rvagg/chai-as-promised": "8.0.1",
"coveralls": "3.1.1",
"cspell": "8.0.0",
"eslint": "8.26.0",
Expand Down
2 changes: 1 addition & 1 deletion test/test-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict';

import chai from 'chai';
import * as chai from 'chai';

import History from '../lib/history.js';

Expand Down
7 changes: 2 additions & 5 deletions test/test-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@

'use strict';

import chai from 'chai';
import chaiImmutable from 'chai-immutable';
import * as chai from 'chai';
import Immutable from 'immutable';
import Job from '../lib/job.js';

const { expect } = chai;
const { List } = Immutable;

chai.use(chaiImmutable);

describe('Job', () => {
describe('object', () => {
it('should be immutable (aka frozen)', () => {
Expand Down Expand Up @@ -48,7 +45,7 @@ describe('Job', () => {
it('should successfully update a list of errors', () => {
const job = new Job().set('errors', new List('error'));

expect(job.get('errors')).to.equal(new List('error'));
expect(job.get('errors')).to.eql(new List('error'));
});

it('should not accept non-string statuses', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/test-json-http-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'use strict';

import chai from 'chai';
import * as chai from 'chai';
import JsonHttpService from '../lib/json-http-service.js';

const { expect } = chai;
Expand Down
20 changes: 7 additions & 13 deletions test/test-orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@

'use strict';

import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import chaiImmutable from 'chai-immutable';
import * as chai from 'chai';
import chaiAsPromised from '@rvagg/chai-as-promised';
import Immutable from 'immutable';
import Promise from 'promise';
import Job from '../lib/job.js';

import Orchestrator from '../lib/orchestrator.js';
import RequestState from '../lib/request-state.js';

const { expect } = chai;
const { assert, expect } = chai;

chai.use(chaiAsPromised);
chai.use(chaiImmutable);

describe('Orchestrator', () => {
describe('hasFinished(state)', () => {
Expand Down Expand Up @@ -126,7 +124,8 @@ describe('Orchestrator', () => {
});

it('should return a list with 2 elements', () => {
expect(resultOk).to.be.an.instanceOf(Immutable.List).and.to.have.size(2);
expect(resultOk).to.be.an.instanceOf(Immutable.List);
assert.equal(resultOk.size, 2);
});

it('should return Promises', () => {
Expand Down Expand Up @@ -156,11 +155,6 @@ describe('Orchestrator', () => {
.get(1)
.then(state => expect(state.jobs.get('dummy').status).to.equal('ok')));

it('should set the second returned state as successful job', () =>
resultOk
.get(1)
.then(state => expect(state.jobs.get('dummy').status).to.equal('ok')));

it('should set the second returned state as failed job', () =>
resultFailure
.get(1)
Expand All @@ -171,7 +165,7 @@ describe('Orchestrator', () => {
it('should return a state with errors when a job fails', () =>
resultFailure
.get(1)
.then(state => expect(state.jobs.get('dummy').errors).to.have.size(1)));
.then(state => assert.equal(state.jobs.get('dummy').errors.size, 1)));

it('should return a failed state when a job fails', () =>
expect(resultFailure.get(1)).to.eventually.have.property(
Expand All @@ -189,7 +183,7 @@ describe('Orchestrator', () => {
it('should return a state with errors when a job errors', () =>
resultError
.get(1)
.then(state => expect(state.jobs.get('dummy').errors).to.have.size(1)));
.then(state => assert(state.jobs.get('dummy').errors.size, 1)));

it('should return an errored state when a job errors', () =>
expect(resultError.get(1)).to.eventually.have.property(
Expand Down
11 changes: 4 additions & 7 deletions test/test-request-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@

'use strict';

import chai from 'chai';
import chaiImmutable from 'chai-immutable';
import * as chai from 'chai';
import Immutable from 'immutable';

import Job from '../lib/job.js';

import RequestState from '../lib/request-state.js';

const { List, Map } = Immutable;
const { expect } = chai;

chai.use(chaiImmutable);
const { assert, expect } = chai;

describe('RequestState', () => {
const state = new RequestState('something', new Map({ dummy: new Job() }));
Expand Down Expand Up @@ -54,7 +51,7 @@ describe('RequestState', () => {
const newState = state.addToHistory('Some random fact');

// TODO Improve test when History is refactored
expect(newState.get('history').facts).to.have.size(1);
assert.equal(newState.get('history').facts.size, 1);
});
});

Expand Down Expand Up @@ -91,7 +88,7 @@ describe('RequestState', () => {
it('should update the status of a specific job', () => {
const newState = state.setJobErrors('dummy', List.of('error'));

expect(newState.get('jobs').get('dummy').get('errors')).to.have.size(1);
assert.equal(newState.get('jobs').get('dummy').get('errors').size, 1);
});

it('should handle inexisting jobs', () => {
Expand Down
43 changes: 29 additions & 14 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
* @module
*/

import chai from 'chai';
import chaiImmutable from 'chai-immutable';
import chaiAsPromised from 'chai-as-promised';
import * as chai from 'chai';
import chaiAsPromised from '@rvagg/chai-as-promised';
import Promise from 'promise';
import Fs from 'fs';
import Immutable from 'immutable';
Expand All @@ -36,10 +35,9 @@ const {
// Switch the environment into testing mode
process.env.NODE_ENV = 'dev';

const { expect } = chai;
const { assert, expect } = chai;
const { List, Map } = Immutable;

chai.use(chaiImmutable);
chai.use(chaiAsPromised);

let pendingTests = 6;
Expand Down Expand Up @@ -109,8 +107,12 @@ describe('DocumentDownloader', () => {
expect(content).to.be.an.instanceOf(Promise);
});

it('should promise a List of size 2', () =>
expect(content).to.eventually.be.an.instanceOf(List).of.size(2));
it('should promise a List of size 2', () => {
expect(content).to.eventually.be.an.instanceOf(List);
content.then(content => {
assert.equal(content.size, 2);
});
});

it('should fetch multiple URLs', () =>
content.then(content => {
Expand Down Expand Up @@ -341,7 +343,9 @@ describe('DocumentDownloader', () => {
'img/image2.jpg',
);

expect(DocumentDownloader.getFilenames(manifest)).to.equal(filenames);
DocumentDownloader.getFilenames(manifest).forEach((v, k) => {
assert.equal(v, filenames.get(k));
});
});
});

Expand Down Expand Up @@ -431,8 +435,11 @@ describe('SpecberusWrapper', () => {
metadata,
);

it('should return an error property that has 1 errors', () =>
expect(content).that.eventually.has.property('errors').that.has.size(1));
it('should return an error property that has 1 errors', () => {
content.then(content => {
assert.equal(content.errors.size, 1);
});
});
});

describe('validate(url-with-css-warnings)', () => {
Expand All @@ -445,8 +452,12 @@ describe('SpecberusWrapper', () => {
metadata,
);

it('should return an error property that has no errors', () =>
expect(content).that.eventually.has.property('errors').that.has.size(0));
it('should return an error property that has no errors', () => {
expect(content).that.eventually.has.property('errors');
content.then(content => {
assert.equal(content.errors.size, 0);
});
});
});

describe('extractMetadata(url)', () => {
Expand Down Expand Up @@ -667,14 +678,18 @@ describe('Publisher', () => {
expect(promise).to.eventually.be.an.instanceOf(List));

it('should return no errors if publication is successful', () =>
expect(promise).to.eventually.be.empty);
promise.then(promise => {
assert.equal(promise.size, 0);
}));

it('should return errors when the publication has failed', () => {
const errPromise = new Publisher(new BadRequestService()).publish(
metadata,
);

return expect(errPromise).to.eventually.have.size(1);
errPromise.then(content => {
assert.equal(content.size, 1);
});
});

it('should reject if not yet implemented', () => {
Expand Down

0 comments on commit dfc85e3

Please sign in to comment.