Skip to content

Commit

Permalink
test: Simplify file testing
Browse files Browse the repository at this point in the history
* Use real (tmp) directories and write real files with 'with-local-tmp-dir' package
  * Removes a bunch of complexity, packages, and hacks to mock FS
* Move ACCEPT/CLOSE tests into log line parsing suite and test string parsing rather than writing to test log
* Organize tests better (describe suites)
  • Loading branch information
FoxxMD committed Feb 21, 2024
1 parent c678f7f commit 097e858
Show file tree
Hide file tree
Showing 13 changed files with 580 additions and 667 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,4 @@ dist

config/*.yaml
config/logs
tmp-*/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ config/*.bak
node_modules
.idea
endlessData
tmp-*/
4 changes: 3 additions & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"reporter": "dot",
"require": ["tsx", "tests/utils/mochaSetup.ts"]
"extension": "ts",
"import": "tsx/esm",
"require": ["tests/utils/mochaSetup.ts"]
}
203 changes: 70 additions & 133 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"yaml": "^2.3.4"
},
"devDependencies": {
"@aleung/fs-monkey": "^1.1.1",
"@faker-js/faker": "^8.4.1",
"@types/async": "^3.2.24",
"@types/chai": "^4.3.11",
Expand All @@ -68,13 +67,13 @@
"@types/triple-beam": "^1.3.5",
"chai": "^4.4.1",
"chai-as-promised": "^7.1.1",
"memfs": "^4.6.0",
"mocha": "^10.3.0",
"msw": "^2.2.0",
"nodemon": "^3.0.3",
"sinon": "^17.0.1",
"sinon-chai": "^3.7.0",
"ts-essentials": "^9.4.1",
"typescript-json-schema": "~0.55"
"typescript-json-schema": "~0.55",
"with-local-tmp-dir": "^5.0.1"
}
}
22 changes: 12 additions & 10 deletions tests/geoLookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ const oneVal: IPDataResponse = {
isp: "Cloudflare, Inc"
}

it('Uses cache for repeat addresses', async function () {
after(function() {
sinon.restore();
});
const lookup = new GeoLookup(logger);
describe('IP Geolocation', () => {
it('Uses cache for repeat addresses', async function () {
after(function() {
sinon.restore();
});
const lookup = new GeoLookup(logger);

const fake = sinon.replace(lookup, 'fetchExternalGeolocation', sinon.fake.returns(Promise.resolve(oneVal)))
const fake = sinon.replace(lookup, 'fetchExternalGeolocation', sinon.fake.returns(Promise.resolve(oneVal)))

await lookup.getInfo(testIp);
await lookup.getInfo(testIp);
await lookup.getInfo(testIp);
assert.equal(fake.callCount, 1)
await lookup.getInfo(testIp);
await lookup.getInfo(testIp);
await lookup.getInfo(testIp);
assert.equal(fake.callCount, 1)
});
});
Loading

0 comments on commit 097e858

Please sign in to comment.