Skip to content

Commit d1fca4a

Browse files
committed
Pulling results from test suite in detox test.
1 parent 66f1df8 commit d1fca4a

File tree

11 files changed

+298
-133
lines changed

11 files changed

+298
-133
lines changed

pnpm-lock.yaml

Lines changed: 8 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/powersynctests/.detoxrc.js

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,82 +2,86 @@
22
module.exports = {
33
testRunner: {
44
args: {
5-
'$0': 'jest',
6-
config: 'e2e/jest.config.js'
5+
$0: 'jest',
6+
config: 'e2e/jest.config.js',
77
},
88
jest: {
9-
setupTimeout: 120000
10-
}
9+
setupTimeout: 120000,
10+
},
1111
},
1212
apps: {
1313
'ios.debug': {
1414
type: 'ios.app',
15-
binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/YOUR_APP.app',
16-
build: 'xcodebuild -workspace ios/YOUR_APP.xcworkspace -scheme YOUR_APP -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build'
15+
binaryPath:
16+
'ios/build/Build/Products/Debug-iphonesimulator/powersynctests.app',
17+
build:
18+
'xcodebuild -workspace ios/powersynctests.xcworkspace -scheme powersynctests -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build',
1719
},
1820
'ios.release': {
1921
type: 'ios.app',
20-
binaryPath: 'ios/build/Build/Products/Release-iphonesimulator/YOUR_APP.app',
21-
build: 'xcodebuild -workspace ios/YOUR_APP.xcworkspace -scheme YOUR_APP -configuration Release -sdk iphonesimulator -derivedDataPath ios/build'
22+
binaryPath:
23+
'ios/build/Build/Products/Release-iphonesimulator/powersynctests.app',
24+
build:
25+
'xcodebuild -workspace ios/powersynctests.xcworkspace -scheme powersynctests -configuration Release -sdk iphonesimulator -derivedDataPath ios/build',
2226
},
2327
'android.debug': {
2428
type: 'android.apk',
2529
binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
26-
build: 'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
27-
reversePorts: [
28-
8081
29-
]
30+
build:
31+
'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
32+
reversePorts: [8081],
3033
},
3134
'android.release': {
3235
type: 'android.apk',
3336
binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
34-
build: 'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release'
35-
}
37+
build:
38+
'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release',
39+
},
3640
},
3741
devices: {
3842
simulator: {
3943
type: 'ios.simulator',
4044
device: {
41-
type: 'iPhone 15'
42-
}
45+
type: 'iPhone 16',
46+
},
4347
},
4448
attached: {
4549
type: 'android.attached',
4650
device: {
47-
adbName: '.*'
48-
}
51+
adbName: '.*',
52+
},
4953
},
5054
emulator: {
5155
type: 'android.emulator',
5256
device: {
53-
avdName: 'Pixel_3a_API_30_x86'
54-
}
55-
}
57+
avdName: 'Pixel_3a_API_30_x86',
58+
},
59+
},
5660
},
5761
configurations: {
5862
'ios.sim.debug': {
5963
device: 'simulator',
60-
app: 'ios.debug'
64+
app: 'ios.debug',
6165
},
6266
'ios.sim.release': {
6367
device: 'simulator',
64-
app: 'ios.release'
68+
app: 'ios.release',
6569
},
6670
'android.att.debug': {
6771
device: 'attached',
68-
app: 'android.debug'
72+
app: 'android.debug',
6973
},
7074
'android.att.release': {
7175
device: 'attached',
72-
app: 'android.release'
76+
app: 'android.release',
7377
},
7478
'android.emu.debug': {
7579
device: 'emulator',
76-
app: 'android.debug'
80+
app: 'android.debug',
7781
},
7882
'android.emu.release': {
7983
device: 'emulator',
80-
app: 'android.release'
81-
}
82-
}
84+
app: 'android.release',
85+
},
86+
},
8387
};

tools/powersynctests/e2e/jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ module.exports = {
1818
},
1919
],
2020
},
21-
transformIgnorePatterns: [],
2221
};
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import 'detox';
2+
import {expect} from 'detox';
3+
import {IndexableNativeElement} from 'detox/detox';
4+
5+
describe('Raw queries', () => {
6+
let testCount = 0;
7+
8+
beforeAll(async () => {
9+
await device.launchApp();
10+
const suiteElement = element(by.id('Raw queries'));
11+
await suiteElement.tap();
12+
13+
const testCounterLabel = ((await suiteElement.getAttributes()) as any)
14+
.label;
15+
testCount = Number(testCounterLabel);
16+
17+
await waitFor(element(by.text('⏳')))
18+
.not.toBeVisible()
19+
.withTimeout(20000);
20+
});
21+
22+
// Since tests need to be defined statically, we need to use a loop to evaluate the tests dynamically
23+
it('should pass all tests', async () => {
24+
const tests: {
25+
title: string;
26+
status: 'passed' | 'failed' | 'pending';
27+
message?: string;
28+
trace?: string;
29+
}[] = [];
30+
for (let i = 0; i < testCount; i++) {
31+
const title = await getText(element(by.id('testtitle-' + i)));
32+
try {
33+
await expect(element(by.id('teststate-' + i))).toHaveText('✅');
34+
35+
tests.push({
36+
title: title,
37+
status: 'passed',
38+
message: 'Test passed',
39+
});
40+
} catch (e) {
41+
try {
42+
await expect(element(by.id('teststate-' + i))).toHaveText('❌');
43+
const errorMessage = await getText(element(by.id('errorstate-' + i)));
44+
tests.push({
45+
title: title,
46+
status: 'failed',
47+
message: errorMessage,
48+
trace: (e as any).message,
49+
});
50+
} catch (_e) {
51+
tests.push({
52+
title: title,
53+
status: 'pending',
54+
});
55+
}
56+
}
57+
}
58+
let hasErrors = !!tests.filter(t => t.status === 'failed').length;
59+
60+
// Dump error traces first
61+
if (hasErrors) {
62+
console.log('\n\x1b[31m\x1b[1m✖ Failed test traces:\x1b[0m\n');
63+
tests.forEach((t, i) => {
64+
if (t.status !== 'failed') {
65+
return;
66+
}
67+
console.log(`\x1b[31m#${i + 1} ${t.title}\n\x1b[37m${t.trace}`);
68+
});
69+
}
70+
71+
// Print final summary
72+
console.log('\n\x1b[1mTest Summary:\x1b[0m');
73+
tests.forEach((t, i) => {
74+
if (t.status === 'passed') {
75+
console.log(`\x1b[32m#${i + 1} ${t.title}\x1b[0m`);
76+
} else if (t.status === 'failed') {
77+
console.log(
78+
`\x1b[31m#${i + 1} ${t.title} - Failed \x1b[37m${t.message}`,
79+
);
80+
} else {
81+
console.log(`\x1b[33m#${i + 1} ${t.title}`);
82+
}
83+
});
84+
85+
if (hasErrors) {
86+
throw new Error('Test suite failed - check the above errors for details');
87+
}
88+
});
89+
});
90+
91+
async function getText(element: IndexableNativeElement): Promise<string> {
92+
return ((await element.getAttributes()) as any).label as string;
93+
}

tools/powersynctests/e2e/starter.test.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)