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
|
# typescript
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
|
||||||
app-example
|
coverage/**/*
|
||||||
ios
|
|
||||||
android
|
|
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.
|
||||||
|
};
|
18
app.json
18
app.json
@ -41,6 +41,24 @@
|
|||||||
"resizeMode": "contain",
|
"resizeMode": "contain",
|
||||||
"backgroundColor": "#ffffff"
|
"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": {
|
"experiments": {
|
||||||
|
@ -14,12 +14,6 @@ export class Message {
|
|||||||
|
|
||||||
constructor (public conversation : Conversation, public speaker : Speaker, public text? : string) {}
|
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() {
|
get otherSpeaker() {
|
||||||
return this.speaker.id === this.conversation.host.id ? this.conversation.guest : this.conversation.host
|
return this.speaker.id === this.conversation.host.id ? this.conversation.guest : this.conversation.host
|
||||||
}
|
}
|
||||||
@ -27,6 +21,13 @@ export class Message {
|
|||||||
get otherLanguage() {
|
get otherLanguage() {
|
||||||
return this.otherSpeaker.language
|
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> {
|
export class Conversation extends Array<Message> {
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import SQLite from "react-native-sqlite-storage"
|
import * as SQLite from 'expo-sqlite';
|
||||||
|
|
||||||
SQLite.enablePromise(true);
|
|
||||||
|
|
||||||
export const MIGRATE_UP = {
|
export const MIGRATE_UP = {
|
||||||
1: [
|
1: [
|
||||||
@ -19,15 +17,12 @@ export const MIGRATE_DOWN = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getDb(migrationDirection : "up" | "down" = "up") {
|
export async function getDb(migrationDirection : "up" | "down" = "up") {
|
||||||
const db = await SQLite.openDatabase({
|
const db = await SQLite.openDatabaseAsync('translation_terrace');
|
||||||
name: "translation_terrace",
|
|
||||||
});
|
|
||||||
|
|
||||||
for (let [migration, statements] of Object.entries(MIGRATE_UP)) {
|
for (let [migration, statements] of Object.entries(MIGRATE_UP)) {
|
||||||
for (let statement of statements) {
|
for (let statement of statements) {
|
||||||
await db.transaction(async (tx) => {
|
console.log(statement)
|
||||||
await tx.executeSql(statement)
|
await db.runAsync(statement);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,30 +1,42 @@
|
|||||||
import { SQLiteDatabase } from "react-native-sqlite-storage";
|
import { SQLiteDatabase } from "expo-sqlite";
|
||||||
|
|
||||||
export class Settings {
|
export class Settings {
|
||||||
|
|
||||||
|
static KEYS = [
|
||||||
|
"host_language",
|
||||||
|
"libretranslate_base_url",
|
||||||
|
'ui_direction',
|
||||||
|
]
|
||||||
|
|
||||||
constructor(public db: SQLiteDatabase) {
|
constructor(public db: SQLiteDatabase) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getValue(key: string) {
|
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 = `
|
const query = `
|
||||||
SELECT ${key}
|
SELECT ?
|
||||||
FROM settings
|
FROM settings
|
||||||
LIMIT 1`
|
LIMIT 1`
|
||||||
const result = await this.db.executeSql(
|
const result = await this.db.getFirstAsync(
|
||||||
query
|
query
|
||||||
);
|
);
|
||||||
|
|
||||||
result[0].rows.item(0).host_language;
|
return result ? (result as any)[key] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setValue(key: string, value: any) {
|
private async setValue(key: string, value: any) {
|
||||||
|
if (!Settings.KEYS.includes(key)) {
|
||||||
|
throw new Error(`Invalid setting: '${key}'`)
|
||||||
|
}
|
||||||
const statement = `INSERT INTO settings (${key})
|
const statement = `INSERT INTO settings (${key})
|
||||||
SELECT '?'
|
SELECT '?'
|
||||||
ON CONFLICT DO UPDATE SET ${key} = ?`
|
ON CONFLICT DO UPDATE SET ${key} = ?`
|
||||||
await this.db.transaction(async (tx) => {
|
await this.db.runAsync(statement, [value, value]);
|
||||||
await tx.executeSql(statement, [value, value]);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async setHostLanguage(value: string) {
|
async setHostLanguage(value: string) {
|
||||||
|
@ -31,7 +31,7 @@ describe('Message Component', () => {
|
|||||||
conversation.addMessage(host, "Hello, how are you?");
|
conversation.addMessage(host, "Hello, how are you?");
|
||||||
await conversation.translateLast();
|
await conversation.translateLast();
|
||||||
|
|
||||||
render(<MessageBubble message={conversation[0]} translator={translator} />);
|
render(<MessageBubble message={conversation[0]} />);
|
||||||
expect(await screen.findByText(translatedText)).toBeOnTheScreen();
|
expect(await screen.findByText(translatedText)).toBeOnTheScreen();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ describe('Message Component', () => {
|
|||||||
const text = "Hello, how are you?"
|
const text = "Hello, how are you?"
|
||||||
const translatedText = 'Hola, ¿cómo estás?';
|
const translatedText = 'Hola, ¿cómo estás?';
|
||||||
conversation.addMessage(host, text);
|
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(text)).toBeOnTheScreen();
|
||||||
expect(await screen.findByText(translatedText)).not.toBeOnTheScreen();
|
expect(await screen.findByText(translatedText)).not.toBeOnTheScreen();
|
||||||
await act(async () => {
|
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",
|
"main": "expo-router/entry",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {
|
"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",
|
"start": "expo start",
|
||||||
"reset-project": "node ./scripts/reset-project.js",
|
"reset-project": "node ./scripts/reset-project.js",
|
||||||
"android": "expo prebuild --pnpm -p android --offline",
|
"android": "expo prebuild --pnpm -p android --offline",
|
||||||
"ios": "expo prebuild --pnpm -p android --offline",
|
"ios": "expo prebuild --pnpm -p android --offline",
|
||||||
"web": "expo start --offline --web",
|
"web": "expo start --offline --web",
|
||||||
"test": "jest --watchAll",
|
|
||||||
"lint": "expo lint"
|
"lint": "expo lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -19,6 +22,7 @@
|
|||||||
"@react-navigation/bottom-tabs": "^7.2.0",
|
"@react-navigation/bottom-tabs": "^7.2.0",
|
||||||
"@react-navigation/native": "^7.0.14",
|
"@react-navigation/native": "^7.0.14",
|
||||||
"@react-navigation/native-stack": "^7.2.0",
|
"@react-navigation/native-stack": "^7.2.0",
|
||||||
|
"expo": "~52.0.28",
|
||||||
"expo-blur": "~14.0.3",
|
"expo-blur": "~14.0.3",
|
||||||
"expo-constants": "~17.0.5",
|
"expo-constants": "~17.0.5",
|
||||||
"expo-font": "~13.0.3",
|
"expo-font": "~13.0.3",
|
||||||
@ -27,6 +31,7 @@
|
|||||||
"expo-router": "~4.0.17",
|
"expo-router": "~4.0.17",
|
||||||
"expo-screen-orientation": "~8.0.4",
|
"expo-screen-orientation": "~8.0.4",
|
||||||
"expo-splash-screen": "~0.29.21",
|
"expo-splash-screen": "~0.29.21",
|
||||||
|
"expo-sqlite": "~15.1.2",
|
||||||
"expo-status-bar": "~2.0.1",
|
"expo-status-bar": "~2.0.1",
|
||||||
"expo-symbols": "~0.2.2",
|
"expo-symbols": "~0.2.2",
|
||||||
"expo-system-ui": "~4.0.7",
|
"expo-system-ui": "~4.0.7",
|
||||||
@ -44,13 +49,31 @@
|
|||||||
"react-native-sqlite-storage": "^6.0.1",
|
"react-native-sqlite-storage": "^6.0.1",
|
||||||
"react-native-web": "~0.19.13",
|
"react-native-web": "~0.19.13",
|
||||||
"react-native-webview": "13.12.5",
|
"react-native-webview": "13.12.5",
|
||||||
"whisper.rn": "^0.3.9",
|
"whisper.rn": "^0.3.9"
|
||||||
"expo": "~52.0.28"
|
},
|
||||||
|
"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": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.26.7",
|
"@babel/core": "^7.26.7",
|
||||||
"@babel/preset-typescript": "^7.26.0",
|
"@babel/preset-typescript": "^7.26.0",
|
||||||
"@jest/globals": "^29.7.0",
|
"@jest/globals": "^29.7.0",
|
||||||
|
"@testing-library/react-native": "^13.0.1",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
"@types/react": "~18.3.18",
|
"@types/react": "~18.3.18",
|
||||||
"@types/react-native-sqlite-storage": "^6.0.5",
|
"@types/react-native-sqlite-storage": "^6.0.5",
|
||||||
@ -58,6 +81,7 @@
|
|||||||
"babel-jest": "^29.7.0",
|
"babel-jest": "^29.7.0",
|
||||||
"babel-plugin-module-resolver": "^5.0.2",
|
"babel-plugin-module-resolver": "^5.0.2",
|
||||||
"expo": "~52.0.28",
|
"expo": "~52.0.28",
|
||||||
|
"expo-sqlite-mock": "^2.0.1",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-expo": "~52.0.3",
|
"jest-expo": "~52.0.3",
|
||||||
"metro-react-native-babel-preset": "^0.77.0",
|
"metro-react-native-babel-preset": "^0.77.0",
|
||||||
|
9873
pnpm-lock.yaml
generated
9873
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user