expo-sqlite-mock 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,14 +3,64 @@
3
3
  [![License: MIT](https://img.shields.io/npm/l/expo-sqlite-mock.svg)](https://github.com/zfben/expo-sqlite-mock/blob/main/packages/faasjs/jest/LICENSE)
4
4
  [![NPM Version](https://img.shields.io/npm/v/expo-sqlite-mock.svg)](https://www.npmjs.com/package/expo-sqlite-mock)
5
5
 
6
- Use expo-sqlite with jest.
6
+ Use [expo-sqlite](https://docs.expo.dev/versions/latest/sdk/sqlite/) with jest.
7
7
 
8
8
  ## Notice
9
9
 
10
- - **~2.0.0** is for expo-sqlite ~52.
10
+ - **~2.0.0** is for expo-sqlite >=52.
11
11
  - **~1.0.0** is for expo-sqlite ~51.
12
12
 
13
13
  ## Usage
14
14
 
15
15
  1. `npm install -D expo-sqlite-mock` or `bun add -D expo-sqlite-mock`
16
16
  2. Add `"setupFilesAfterEnv": ["expo-sqlite-mock/src/setup.ts"]` and `"testTimeout": 10000` to your jest config (It's in `package.json` for default expo project).
17
+
18
+ Example:
19
+
20
+ ```json
21
+ {
22
+ "jest": {
23
+ "preset": "jest-expo",
24
+ "setupFilesAfterEnv": ["expo-sqlite-mock/src/setup.ts"],
25
+ "testTimeout": 10000
26
+ }
27
+ }
28
+ ```
29
+
30
+ ### Advanced
31
+
32
+ You can set the `EXPO_SQLITE_MOCK` environment variable to a custom SQLite database location.
33
+
34
+ Tips:
35
+
36
+ 1. Please use `JEST_WORKER_ID` to avoid concurrent test cases writing to the same file.
37
+ 2. Update your `.gitignore` to ignore the SQLite database file.
38
+
39
+ Example:
40
+
41
+ ```ts
42
+ it("test", async () => {
43
+ // or you can set it beforeAll or beforeEach
44
+ process.env.EXPO_SQLITE_MOCK = `${__dirname}/test_${process.env.JEST_WORKER_ID}.db`;
45
+
46
+ // your test code
47
+
48
+ // clear the env var
49
+ delete process.env.EXPO_SQLITE_MOCK;
50
+ });
51
+ ```
52
+
53
+ ## Changelog
54
+
55
+ - **2.1.0**
56
+ - Support custom SQLite database location by setting the `EXPO_SQLITE_MOCK` environment variable.
57
+ - Update peer dependencies.
58
+
59
+ - **2.0.1**
60
+ - Fix setup.
61
+
62
+ - **2.0.0**
63
+ - Update for expo-sqlite ~52.
64
+
65
+ - **1.0.0**
66
+ - Initial version.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-sqlite-mock",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/zfben/expo-sqlite-mock",
6
6
  "repository": {
@@ -11,10 +11,11 @@
11
11
  "url": "https://github.com/zfben/expo-sqlite-mock/issues"
12
12
  },
13
13
  "scripts": {
14
- "test": "jest --coverage --forceExit --detectOpenHandles --testTimeout=10000"
14
+ "test": "jest --coverage --forceExit --testTimeout=10000"
15
15
  },
16
16
  "jest": {
17
17
  "preset": "jest-expo",
18
+ "testEnvironment": "node",
18
19
  "testRegex": "/*\\.test\\.tsx?$"
19
20
  },
20
21
  "files": [
@@ -25,19 +26,21 @@
25
26
  "better-sqlite3": "*",
26
27
  "jest": "*",
27
28
  "expo-sqlite": "*",
28
- "expo": "~52"
29
+ "expo": ">=52"
29
30
  },
30
31
  "devDependencies": {
31
32
  "typescript": "*",
32
- "@biomejs/biome": "*",
33
+ "@faasjs/lint": "*",
33
34
  "expo-sqlite": "*",
34
35
  "better-sqlite3": "*",
35
36
  "@types/better-sqlite3": "*",
36
- "@types/react": "*",
37
- "react": "*",
38
- "react-test-renderer": "18.3.1",
39
- "@faasjs/jest": "*",
37
+ "@types/react": "^18",
38
+ "react": "^18",
39
+ "react-test-renderer": "^18",
40
+ "react-native": "~0.77",
40
41
  "@testing-library/react-native": "*",
41
- "jest-expo": "~52"
42
+ "jest-expo": "~52",
43
+ "@types/jest": "*",
44
+ "jest": "*"
42
45
  }
43
46
  }
@@ -45,7 +45,7 @@ class NativeDatabase {
45
45
  if (serializedData != null) {
46
46
  this.sqlite3Db = new sqlite3(Buffer.from(serializedData))
47
47
  } else {
48
- this.sqlite3Db = new sqlite3(':memory:')
48
+ this.sqlite3Db = new sqlite3(process.env.EXPO_SQLITE_MOCK || ':memory:')
49
49
  }
50
50
  dbs.push(this)
51
51
  }
package/src/setup.ts CHANGED
@@ -1,13 +1,8 @@
1
1
  import { mockedExpoSqliteNext } from './ExpoSQLiteNext'
2
- import { existsSync } from 'node:fs'
3
2
 
4
- if (existsSync(`${__dirname}/../../expo-sqlite/build/ExpoSQLiteNext`))
5
- jest.mock(`${__dirname}/../../expo-sqlite/build/ExpoSQLiteNext`, () => mockedExpoSqliteNext)
6
- else {
7
- jest.mock(`${__dirname}/../../expo-sqlite/build/ExpoSQLite`, () => mockedExpoSqliteNext)
8
- jest.mock(`${__dirname}/../../expo-sqlite/build/pathUtils`, () => ({
9
- createDatabasePath: jest.fn().mockImplementation((databaseName: string) => {
10
- return databaseName
11
- }),
12
- }))
13
- }
3
+ jest.mock(`${__dirname}/../../expo-sqlite/build/ExpoSQLite`, () => mockedExpoSqliteNext)
4
+ jest.mock(`${__dirname}/../../expo-sqlite/build/pathUtils`, () => ({
5
+ createDatabasePath: jest.fn().mockImplementation((databaseName: string) => {
6
+ return databaseName
7
+ }),
8
+ }))