-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from LinusU/v2
💥 Change API to return Promises
- Loading branch information
Showing
7 changed files
with
90 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ node_js: | |
- 12 | ||
- 10 | ||
- 8 | ||
- 6 | ||
- 4 | ||
- 8.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare class ApplicationConfig { | ||
filePath: string | ||
read(): Promise<unknown> | ||
write(data: object): Promise<void> | ||
trash(): Promise<void> | ||
} | ||
|
||
declare function createApplicationConfig (mame: String): ApplicationConfig | ||
export = createApplicationConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,25 @@ | |
"name": "application-config", | ||
"version": "1.0.1", | ||
"license": "MIT", | ||
"author": "Linus Unnebäck <[email protected]>", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/LinusU/node-application-config.git" | ||
"repository": "LinusU/node-application-config", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"scripts": { | ||
"test": "standard && mocha" | ||
}, | ||
"dependencies": { | ||
"application-config-path": "^0.1.0", | ||
"mkdirp": "^0.5.1" | ||
"load-json-file": "^6.2.0", | ||
"write-json-file": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.1.0", | ||
"standard": "*" | ||
"assert-rejects": "^1.0.0", | ||
"mocha": "^6.2.2", | ||
"standard": "^14.3.1" | ||
}, | ||
"scripts": { | ||
"test": "standard && mocha" | ||
"engines": { | ||
"node": ">=8.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,41 @@ | ||
/* eslint-env mocha */ | ||
|
||
var lib = require('./')('linusu-test') | ||
var fs = require('fs') | ||
var assert = require('assert') | ||
const lib = require('./')('linusu-test') | ||
const fs = require('fs') | ||
const assert = require('assert') | ||
const assertRejects = require('assert-rejects') | ||
|
||
var payload = { n: 1337 } | ||
const payload = { n: 1337 } | ||
|
||
describe('application-config', function () { | ||
it('should write', function (done) { | ||
lib.write(payload, done) | ||
describe('application-config', () => { | ||
it('should write', async () => { | ||
await lib.write(payload) | ||
}) | ||
|
||
it('should read', function (done) { | ||
lib.read(function (err, data) { | ||
assert.ifError(err) | ||
assert.strictEqual(payload.n, data.n) | ||
|
||
done() | ||
}) | ||
it('should read', async () => { | ||
assert.deepStrictEqual(await lib.read(), payload) | ||
}) | ||
|
||
it('should export path to file', function (done) { | ||
it('should export path to file', () => { | ||
assert.strictEqual(typeof lib.filePath, 'string') | ||
|
||
fs.readFile(lib.filePath, function (err, raw) { | ||
assert.ifError(err) | ||
assert.deepStrictEqual(JSON.parse(raw.toString()), payload) | ||
|
||
done() | ||
}) | ||
const raw = fs.readFileSync(lib.filePath) | ||
assert.deepStrictEqual(JSON.parse(raw.toString()), payload) | ||
}) | ||
|
||
it('should trash', function (done) { | ||
lib.trash(done) | ||
it('should trash', async () => { | ||
await lib.trash() | ||
}) | ||
|
||
it('should be gone', function (done) { | ||
lib.read(function (err, data) { | ||
assert.ifError(err) | ||
assert.strictEqual(undefined, data.n) | ||
|
||
done() | ||
}) | ||
it('should be gone', async () => { | ||
assert.deepStrictEqual(await lib.read(), {}) | ||
}) | ||
|
||
it('should throw', function () { | ||
assert.throws(function () { | ||
lib.write() | ||
}, TypeError) | ||
|
||
assert.throws(function () { | ||
lib.write(null) | ||
}, TypeError) | ||
|
||
assert.throws(function () { | ||
lib.write(undefined) | ||
}, TypeError) | ||
|
||
assert.throws(function () { | ||
lib.write(1) | ||
}, TypeError) | ||
|
||
assert.throws(function () { | ||
lib.write('test') | ||
}, TypeError) | ||
it('should throw', () => { | ||
assertRejects(lib.write(), TypeError) | ||
assertRejects(lib.write(null), TypeError) | ||
assertRejects(lib.write(undefined), TypeError) | ||
assertRejects(lib.write(1), TypeError) | ||
assertRejects(lib.write('test'), TypeError) | ||
}) | ||
}) |