Skip to content

Commit

Permalink
Resolve small test issue, import issue, remove extra files from publish
Browse files Browse the repository at this point in the history
  • Loading branch information
eslachance committed May 17, 2024
1 parent 567ff03 commit 79b436d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ out/
!.yarn/sdks
!.yarn/versions
.retype/
coverage/
coverage/
tmp/
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"build-api-docs": "node ./scripts/build-docs.js",
"build-docs": "cd docs && npx retype build"
},
"files": [
"src",
"typings"
],
"repository": {
"type": "git",
"url": "git+https://github.com/eslachance/enmap.git"
Expand Down
14 changes: 9 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class Enmap {
});
}

// MARK: Set Methods

/**
* Sets a value in Enmap. If the key already has a value, overwrites the data (or the value in a path, if provided).
* @param {string} key Required. The location in which the data should be saved.
Expand Down Expand Up @@ -391,7 +393,7 @@ class Enmap {
this.set(key, data, path);
}

// AWESOME MATHEMATICAL METHODS
// MARK: Math Methods

/**
* Executes a mathematical operation on a value and saves it in the enmap.
Expand Down Expand Up @@ -657,7 +659,11 @@ class Enmap {
for (const entry of parsedData.keys) {
const { key, value } = entry;
if (!overwrite && this.has(key)) continue;
this.#set(key, value);
this.#db
.prepare(
`INSERT OR REPLACE INTO ${this.#name} (key, value) VALUES (?, ?)`,
)
.run(key, value);
}
}

Expand Down Expand Up @@ -995,7 +1001,7 @@ class Enmap {
return results;
}

// INTERNAL METHODS
// MARK: Internal Methods

/*
* Internal method used to insert or update a key in the database without circular calls to ensure() or others.
Expand Down Expand Up @@ -1046,8 +1052,6 @@ class Enmap {
return parsed;
}

/* INTERNAL METHOD */

#keycheck(key, type = 'key') {
if (!NAME_REGEX.test(key)) {
throw new Error(
Expand Down
11 changes: 4 additions & 7 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
describe,
beforeAll,
test,
beforeEach,
afterEach,
expect,
vi,
} from 'vitest';
Expand Down Expand Up @@ -58,22 +55,22 @@ describe('Enmap', () => {
});

test('should create a persistent Enmap w/ dir', async () => {
await mkdir('/tmp/data').catch(() => {});
await mkdir('./tmp').catch(() => {});

const enmap = new Enmap({ name: 'test', dataDir: '/tmp/data' });
const enmap = new Enmap({ name: 'test', dataDir: './tmp' });

expect(enmap).toBeInstanceOf(Enmap);
});

test('should load a persistent Enmap w/ dir', () => {
const enmap = new Enmap({ name: 'test', dataDir: '/tmp/data' });
const enmap = new Enmap({ name: 'test', dataDir: './tmp' });

expect(enmap).toBeInstanceOf(Enmap);
});

test('should fail to create a persistent Enmap w/o dir', async () => {
expect(
() => new Enmap({ name: 'test', dataDir: '/tmp/data-not-found' }),
() => new Enmap({ name: 'test', dataDir: './data-not-found' }),
).toThrow(TypeError);
});

Expand Down

0 comments on commit 79b436d

Please sign in to comment.