Skip to content

Commit

Permalink
Remove chai-as-promised
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Jan 27, 2024
1 parent a46cec7 commit e0a930b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 101 deletions.
4 changes: 0 additions & 4 deletions mocha.setup.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { use } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { reset } from 'testdouble';

use(chaiAsPromised);

const env = { ...process.env };
process.env = {
NODE_ENV: 'test',
Expand Down
139 changes: 57 additions & 82 deletions package-lock.json

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

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test": "mocha",
"test:coverage": "c8 mocha",
"preversion": "npm test",
"postinstall": "husky install || true"
"postinstall": "husky || true"
},
"author": "Myrotvorets <[email protected]> (https://myrotvorets.center/)",
"license": "MIT",
Expand All @@ -37,7 +37,6 @@
"devDependencies": {
"@myrotvorets/eslint-config-myrotvorets-ts": "^2.24.0",
"@types/chai": "^4.3.11",
"@types/chai-as-promised": "^7.1.8",
"@types/debug": "^4.1.12",
"@types/localtunnel": "^2.0.4",
"@types/mocha": "^10.0.6",
Expand All @@ -47,7 +46,6 @@
"better-sqlite3": "^9.3.0",
"c8": "^9.1.0",
"chai": "^5.0.3",
"chai-as-promised": "^7.1.1",
"eslint-formatter-gha": "^1.4.3",
"eslint-plugin-mocha": "^10.2.0",
"husky": "^9.0.6",
Expand Down
4 changes: 2 additions & 2 deletions test/functional/lib/db.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('Database', function () {

it('should insert a new row', async function () {
await addPost(trx, 1);
return expect(trx.select<Post>('post_id').from('posts').where('post_id', 1).first()).to.eventually.not.be
.undefined;
const post = await trx.select<Post>('post_id').from('posts').where('post_id', 1).first();
return expect(post).not.be.undefined;
});

it('should return an array with the new post ID', async function () {
Expand Down
7 changes: 5 additions & 2 deletions test/unit/lib/utils.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,15 @@ describe('Utils', function () {

it('should throw when the file cannot be located', function () {
when(statMock(matchers.isA(String) as string)).thenReject(new Error());
return expect(findFile('package.json')).to.be.rejectedWith(Error);
return findFile('package.json').then(
() => expect.fail('Should have thrown'),
(err) => expect(err).to.be.an('Error'),
);
});

it('should retrieve name and version from package.json', function () {
when(statMock(matchers.isA(String) as string)).thenResolve({ isFile: () => true });
return expect(findFile('package.json')).to.be.fulfilled;
return findFile('package.json').then((result) => expect(result).to.be.a('string'));
});
});
});
17 changes: 9 additions & 8 deletions test/unit/lib/wpapi.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('wpapi', function () {
});

describe('getPosts', function () {
it('should properly extract data', function () {
it('should properly extract data', async function () {
when(fetchMock(matchers.isA(String) as string)).thenResolve(new Response(JSON.stringify(getPostsResponse)));

const expected: PostData[] = [
Expand All @@ -41,27 +41,28 @@ describe('wpapi', function () {
},
];

return expect(getPosts('https://example.test')).to.become(expected);
const post = await getPosts('https://example.test');
return expect(post).to.deep.equal(expected);
});
});

describe('getFeaturedImageURL', function () {
it('should return image URL', function () {
it('should return image URL', async function () {
when(fetchMock(matchers.isA(String) as string)).thenResolve(
new Response(JSON.stringify(getFeaturedImageResponse)),
);

return expect(getFeaturedImageUrl('https://example.test', 43762)).to.become(
'https://myrotvorets.news/wp-content/uploads/2019/10/Screenshot_5-3.png',
);
const url = await getFeaturedImageUrl('https://example.test', 43762);
return expect(url).to.equal('https://myrotvorets.news/wp-content/uploads/2019/10/Screenshot_5-3.png');
});

it('should return empty URL if the original image URL is malformed', function () {
it('should return empty URL if the original image URL is malformed', async function () {
when(fetchMock(matchers.isA(String) as string)).thenResolve(
new Response(JSON.stringify(getFeaturedImageResponseBadURL)),
);

return expect(getFeaturedImageUrl('https://example.test', 43762)).to.become('');
const url = await getFeaturedImageUrl('https://example.test', 43762);
return expect(url).to.equal('');
});
});
});

0 comments on commit e0a930b

Please sign in to comment.