remove pnpm as package manager. fix jest test issues. use npm for now.
This commit is contained in:
parent
97ca20ed57
commit
58a3829347
4
.gitignore
vendored
4
.gitignore
vendored
@ -35,6 +35,4 @@ yarn-error.*
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
|
||||
app-example
|
||||
ios
|
||||
android
|
||||
coverage/**/*
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"jestTestExplorer.pathToJest": "./node_modules/.bin/jest"
|
||||
}
|
4
__mocks__/expo-sqlite.js
Normal file
4
__mocks__/expo-sqlite.js
Normal file
@ -0,0 +1,4 @@
|
||||
export const SQLite = {
|
||||
openDatabaseAsync: jest.fn(),
|
||||
// Mock other necessary methods like closeDatabase, etc.
|
||||
};
|
20
app.json
20
app.json
@ -41,10 +41,28 @@
|
||||
"resizeMode": "contain",
|
||||
"backgroundColor": "#ffffff"
|
||||
}
|
||||
],
|
||||
[
|
||||
"expo-sqlite",
|
||||
{
|
||||
"enableFTS": true,
|
||||
"useSQLCipher": true,
|
||||
"android": {
|
||||
// Override the shared configuration for Android
|
||||
"enableFTS": false,
|
||||
"useSQLCipher": false
|
||||
},
|
||||
"ios": {
|
||||
// You can also override the shared configurations for iOS
|
||||
"customBuildFlags": [
|
||||
"-DSQLITE_ENABLE_DBSTAT_VTAB=1 -DSQLITE_ENABLE_SNAPSHOT=1"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"experiments": {
|
||||
"typedRoutes": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,12 +14,6 @@ export class Message {
|
||||
|
||||
constructor (public conversation : Conversation, public speaker : Speaker, public text? : string) {}
|
||||
|
||||
public async translate() {
|
||||
const translator = this.conversation.translator
|
||||
if (!this.text) throw new Error("No text")
|
||||
this.translation = await translator.translate(this.text, this.otherLanguage);
|
||||
}
|
||||
|
||||
get otherSpeaker() {
|
||||
return this.speaker.id === this.conversation.host.id ? this.conversation.guest : this.conversation.host
|
||||
}
|
||||
@ -27,6 +21,13 @@ export class Message {
|
||||
get otherLanguage() {
|
||||
return this.otherSpeaker.language
|
||||
}
|
||||
|
||||
public async translate() {
|
||||
const translator = this.conversation.translator
|
||||
if (!this.text) throw new Error("No text")
|
||||
console.log("Translating from %s -> %s", this.speaker.language, this.otherSpeaker.language);
|
||||
this.translation = await translator.translate(this.text, this.otherLanguage);
|
||||
}
|
||||
}
|
||||
|
||||
export class Conversation extends Array<Message> {
|
||||
|
@ -1,6 +1,4 @@
|
||||
import SQLite from "react-native-sqlite-storage"
|
||||
|
||||
SQLite.enablePromise(true);
|
||||
import * as SQLite from 'expo-sqlite';
|
||||
|
||||
export const MIGRATE_UP = {
|
||||
1: [
|
||||
@ -19,15 +17,12 @@ export const MIGRATE_DOWN = {
|
||||
}
|
||||
|
||||
export async function getDb(migrationDirection : "up" | "down" = "up") {
|
||||
const db = await SQLite.openDatabase({
|
||||
name: "translation_terrace",
|
||||
});
|
||||
const db = await SQLite.openDatabaseAsync('translation_terrace');
|
||||
|
||||
for (let [migration, statements] of Object.entries(MIGRATE_UP)) {
|
||||
for (let statement of statements) {
|
||||
await db.transaction(async (tx) => {
|
||||
await tx.executeSql(statement)
|
||||
});
|
||||
console.log(statement)
|
||||
await db.runAsync(statement);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,30 +1,42 @@
|
||||
import { SQLiteDatabase } from "react-native-sqlite-storage";
|
||||
import { SQLiteDatabase } from "expo-sqlite";
|
||||
|
||||
export class Settings {
|
||||
|
||||
static KEYS = [
|
||||
"host_language",
|
||||
"libretranslate_base_url",
|
||||
'ui_direction',
|
||||
]
|
||||
|
||||
constructor(public db: SQLiteDatabase) {
|
||||
|
||||
}
|
||||
|
||||
private async getValue(key: string) {
|
||||
// For security...ensure key is a valid value
|
||||
if (!Settings.KEYS.includes(key)) {
|
||||
throw new Error(`Invalid setting: '${key}'`)
|
||||
}
|
||||
|
||||
const query = `
|
||||
SELECT ${key}
|
||||
SELECT ?
|
||||
FROM settings
|
||||
LIMIT 1`
|
||||
const result = await this.db.executeSql(
|
||||
const result = await this.db.getFirstAsync(
|
||||
query
|
||||
);
|
||||
|
||||
result[0].rows.item(0).host_language;
|
||||
return result ? (result as any)[key] : null;
|
||||
}
|
||||
|
||||
private async setValue(key: string, value: any) {
|
||||
if (!Settings.KEYS.includes(key)) {
|
||||
throw new Error(`Invalid setting: '${key}'`)
|
||||
}
|
||||
const statement = `INSERT INTO settings (${key})
|
||||
SELECT '?'
|
||||
ON CONFLICT DO UPDATE SET ${key} = ?`
|
||||
await this.db.transaction(async (tx) => {
|
||||
await tx.executeSql(statement, [value, value]);
|
||||
})
|
||||
await this.db.runAsync(statement, [value, value]);
|
||||
}
|
||||
|
||||
async setHostLanguage(value: string) {
|
||||
|
@ -31,7 +31,7 @@ describe('Message Component', () => {
|
||||
conversation.addMessage(host, "Hello, how are you?");
|
||||
await conversation.translateLast();
|
||||
|
||||
render(<MessageBubble message={conversation[0]} translator={translator} />);
|
||||
render(<MessageBubble message={conversation[0]} />);
|
||||
expect(await screen.findByText(translatedText)).toBeOnTheScreen();
|
||||
});
|
||||
|
||||
@ -39,7 +39,7 @@ describe('Message Component', () => {
|
||||
const text = "Hello, how are you?"
|
||||
const translatedText = 'Hola, ¿cómo estás?';
|
||||
conversation.addMessage(host, text);
|
||||
render(<MessageBubble message={conversation[0]} translator={translator} />);
|
||||
render(<MessageBubble message={conversation[0]} />);
|
||||
expect(await screen.findByText(text)).toBeOnTheScreen();
|
||||
expect(await screen.findByText(translatedText)).not.toBeOnTheScreen();
|
||||
await act(async () => {
|
||||
|
@ -1,20 +0,0 @@
|
||||
// jest.config.ts
|
||||
import { resolve } from "path"
|
||||
const jestExpoPreset = require('jest-expo/jest-preset');
|
||||
|
||||
const jestConfig = {
|
||||
// preset: 'jest-expo',
|
||||
...jestExpoPreset,
|
||||
// preset: 'ts-jest',
|
||||
transform: {
|
||||
'^.+\\.(ts|tsx)$': 'babel-jest',
|
||||
},
|
||||
moduleNameMapper: {
|
||||
'@': "<rootDir>"
|
||||
},
|
||||
transformIgnorePatterns: [
|
||||
...jestExpoPreset.transformIgnorePatterns,
|
||||
]
|
||||
}
|
||||
|
||||
export default jestConfig
|
@ -1,5 +0,0 @@
|
||||
import jest from "@babel/preset-typescript"
|
||||
|
||||
jest.mock('@react-native-async-storage/async-storage', () =>
|
||||
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
|
||||
);
|
16435
package-lock.json
generated
Normal file
16435
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@ -3,12 +3,15 @@
|
||||
"main": "expo-router/entry",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "jest --watch --coverage=false --changedSince=origin/main",
|
||||
"testDebug": "jest -o --watch --coverage=false",
|
||||
"testFinal": "jest",
|
||||
"updateSnapshots": "jest -u --coverage=false",
|
||||
"start": "expo start",
|
||||
"reset-project": "node ./scripts/reset-project.js",
|
||||
"android": "expo prebuild --pnpm -p android --offline",
|
||||
"ios": "expo prebuild --pnpm -p android --offline",
|
||||
"web": "expo start --offline --web",
|
||||
"test": "jest --watchAll",
|
||||
"lint": "expo lint"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -19,6 +22,7 @@
|
||||
"@react-navigation/bottom-tabs": "^7.2.0",
|
||||
"@react-navigation/native": "^7.0.14",
|
||||
"@react-navigation/native-stack": "^7.2.0",
|
||||
"expo": "~52.0.28",
|
||||
"expo-blur": "~14.0.3",
|
||||
"expo-constants": "~17.0.5",
|
||||
"expo-font": "~13.0.3",
|
||||
@ -27,6 +31,7 @@
|
||||
"expo-router": "~4.0.17",
|
||||
"expo-screen-orientation": "~8.0.4",
|
||||
"expo-splash-screen": "~0.29.21",
|
||||
"expo-sqlite": "~15.1.2",
|
||||
"expo-status-bar": "~2.0.1",
|
||||
"expo-symbols": "~0.2.2",
|
||||
"expo-system-ui": "~4.0.7",
|
||||
@ -44,13 +49,31 @@
|
||||
"react-native-sqlite-storage": "^6.0.1",
|
||||
"react-native-web": "~0.19.13",
|
||||
"react-native-webview": "13.12.5",
|
||||
"whisper.rn": "^0.3.9",
|
||||
"expo": "~52.0.28"
|
||||
"whisper.rn": "^0.3.9"
|
||||
},
|
||||
"jest": {
|
||||
"preset": "jest-expo",
|
||||
"transformIgnorePatterns": [
|
||||
"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)"
|
||||
],
|
||||
"collectCoverage": true,
|
||||
"collectCoverageFrom": [
|
||||
"**/*.{ts,tsx,js,jsx}",
|
||||
"!**/coverage/**",
|
||||
"!**/node_modules/**",
|
||||
"!**/babel.config.js",
|
||||
"!**/expo-env.d.ts",
|
||||
"!**/.expo/**"
|
||||
],
|
||||
"automock": false,
|
||||
"setupFilesAfterEnv": ["expo-sqlite-mock/src/setup.ts"],
|
||||
"testTimeout": 10000
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.26.7",
|
||||
"@babel/preset-typescript": "^7.26.0",
|
||||
"@jest/globals": "^29.7.0",
|
||||
"@testing-library/react-native": "^13.0.1",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/react": "~18.3.18",
|
||||
"@types/react-native-sqlite-storage": "^6.0.5",
|
||||
@ -58,6 +81,7 @@
|
||||
"babel-jest": "^29.7.0",
|
||||
"babel-plugin-module-resolver": "^5.0.2",
|
||||
"expo": "~52.0.28",
|
||||
"expo-sqlite-mock": "^2.0.1",
|
||||
"jest": "^29.7.0",
|
||||
"jest-expo": "~52.0.3",
|
||||
"metro-react-native-babel-preset": "^0.77.0",
|
||||
|
10103
pnpm-lock.yaml
generated
10103
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user