Skip to content

Commit

Permalink
3 tests passing
Browse files Browse the repository at this point in the history
work comms failing
  • Loading branch information
Mattk70 committed Oct 26, 2023
1 parent 81062ba commit 2f10efc
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 20 deletions.
Binary file added intro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,6 @@ window.onload = async () => {
colourmap.value = config.colormap;
// Nocmig mode state
console.log('nocmig mode is ' + config.detect.nocmig);

// Audio preferences:
audioFormat.value = config.audio.format;
audioBitrate.value = config.audio.bitrate;
Expand Down Expand Up @@ -1447,6 +1446,7 @@ window.onload = async () => {
}
)
// establish the message channel

setUpWorkerMessaging()

// Set footer year
Expand Down
8 changes: 6 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ app.whenReady().then(async () => {
// Read the contents of the file synchronously
const fileContent = fs.readFileSync(filePath, 'utf-8');
const config = JSON.parse(fileContent);
DEBUG = config.debug;
DEBUG = process.env.CI === 'e2e' ? false : config.debug;
console.log('CI mode' , process.env.CI)
}
catch (error) {
// Handle errors, for example, file not found
Expand All @@ -348,6 +349,9 @@ app.whenReady().then(async () => {
ipcMain.on('request-worker-channel', (event) => {
// For security reasons, let's make sure only the frames we expect can
// access the worker.
console.log('event.senderfromae ', event.senderFrame)
console.log('mainWindow.webContents.mainFrame ', mainWindow.webContents.mainFrame)
console.log('mainWindow.webContents.mainFrame = event.senderfromae', mainWindow.webContents.mainFrame === event.senderFrame)
if (event.senderFrame === mainWindow.webContents.mainFrame) {
// Create a new channel ...
const { port1, port2 } = new MessageChannelMain()
Expand All @@ -358,7 +362,7 @@ app.whenReady().then(async () => {
// Now the main window and the worker can communicate with each other
// without going through the main process!
}
// Listen for the 'update-variable' message from the renderer process
// Listen for the 'unsaved-records' message from the renderer process
ipcMain.on('unsaved-records', (_event, data) => {
unsavedRecords = data.newValue; // Update the variable with the new value
console.log('Unsaved records:', unsavedRecords);
Expand Down
42 changes: 25 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
"main": "main.js",
"scripts": {
"start": "electron .",
"export": "electron-builder build -w --x64 ",
"export": "electron-builder build -m ",
"publish": "electron-builder --win -p always",
"minify": "terser js/*.js --output dist",
"postpack": "npm run minify"
"test": "./test/playwright.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mattk70/Chirpity-Electron.git"
},
"build": {
"publish": [{
"provider": "github",
"owner": "Mattk70",
"repo": "https://github.com/Mattk70/Chirpity-Electron"
}],
"publish": [
{
"provider": "github",
"owner": "Mattk70",
"repo": "https://github.com/Mattk70/Chirpity-Electron"
}
],
"files": [
"**/*",
"!test*${/*}",
Expand All @@ -45,7 +46,9 @@
"node_modules/ffprobe-static-electron/index.js",
"node_modules/ffprobe-static-electron/package.json"
],
"extraResources": ["./Help/example.mp3"],
"extraResources": [
"./Help/example.mp3"
],
"fileAssociations": [
{
"ext": "mp3",
Expand Down Expand Up @@ -134,7 +137,9 @@
]
},
"win": {
"publish": ["github"],
"publish": [
"github"
],
"verifyUpdateCodeSignature": false,
"asar": true,
"icon": "./img/icon/icon.png",
Expand Down Expand Up @@ -165,30 +170,33 @@
},
"homepage": "https://github.com/mattk70/Chirpity-Electron#readme",
"devDependencies": {
"@playwright/test": "^1.39.0",
"@tensorflow/tfjs-converter": "4.10.0",
"electron": "^25.3.0",
"electron-builder": "24.6.4",
"@tensorflow/tfjs-converter": "4.10.0",
"terser": "5.22.0"
"electron-playwright-helpers": "^1.6.0",
"playwright": "^1.39.0",
"jimp": "0.22.10"
},
"dependencies": {
"@popperjs/core": "^2.9.2",
"@tensorflow/tfjs-node": "4.10.0",
"axios": "1.5.1",
"bootstrap": "5.2.2",
"browser-id3-writer": "^4.4.0",
"colormap": "^2.3.2",
"electron-log": "4.4.8",
"electron-settings": "^4.0.2",
"electron-updater": "6.1.4",
"fast-png": "^6.1.0",
"ffmpeg-static-electron": "^2.0.3",
"fluent-ffmpeg": "^2.1.2",
"jquery": "3.6.3",
"sqlite3": "^5.1.6",
"suncalc": "^1.9.0",
"utimes": "^5.1.1",
"uuid": "^8.3.2",
"wavefile-reader": "^1.1.1",
"wavesurfer.js": "^6.6.3",
"utimes": "^5.1.1",
"electron-updater": "6.1.4",
"electron-log": "4.4.8",
"axios": "1.5.1"
"wavesurfer.js": "^6.6.3"
}
}
8 changes: 8 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { PlaywrightTestConfig } from '@playwright/test'

const config: PlaywrightTestConfig = {
testDir: './test',
maxFailures: 2,
}

export default config
162 changes: 162 additions & 0 deletions test/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import { _electron as electron } from 'playwright'
import { test, expect } from '@playwright/test'
import {
findLatestBuild,
ipcMainCallFirstListener,
ipcRendererCallFirstListener,
parseElectronApp,
ipcMainInvokeHandler,
ipcRendererInvoke,
ipcRendererSend,
ipcMainEmit,
stubMultipleDialogs
} from 'electron-playwright-helpers'
import { ElectronApplication, Page } from 'playwright'
import jimp from 'jimp'
import { ipcMain } from 'electron'
let electronApp: ElectronApplication
let page: Page
let worker: Page
let example_file: any

test.beforeAll(async () => {
// find the latest build in the out directory
const latestBuild = findLatestBuild('./dist')
// parse the directory and find paths and other info
const appInfo = parseElectronApp(latestBuild)
// set the CI environment variable to true
process.env.CI = 'e2e'
electronApp = await electron.launch({
args: [appInfo.main],
executablePath: appInfo.executable
})

example_file = await ipcMainInvokeHandler(electronApp, 'getAudio')
console.log('Example file:' , example_file)
await stubMultipleDialogs(electronApp, [
{
method: 'showOpenDialog',
value: {
filePaths: [example_file],
canceled: false,
},
},
{
method: 'showSaveDialog',
value: {
filePath: '/path/to/file',
canceled: false,
},
},
])

worker = await electronApp.firstWindow();

electronApp.on('window', async (window) => {
const filename = window.url()?.split('/').pop()
console.log(`Window opened: ${filename}`)
page = window
// capture errors
page.on('pageerror', (error) => {
console.error(error)
})
// capture console messages
page.on('console', (msg) => {
console.log(msg.text())
})
})

})

test.afterAll(async () => {
await electronApp.close()
})

test('Page title is correct', async () => {
page = await electronApp.waitForEvent('window')

page.pause()
const title = await page.title()
expect(title).toBe('Chirpity Bird Call Detection')
})


test(`"Open File" works`, async () => {
const fileMenu = await page.$('#navbarDropdown')
await fileMenu?.click()
const fileOpen = await page.$('#open')
expect(fileOpen).toBeTruthy()
await fileOpen?.click();
const fileName = await page.$('#spectrogram')
expect(fileName).toBeTruthy()
await page.screenshot({ path: 'intro.png' })

})


// test('send IPC message from renderer', async () => {
// // evaluate this script in render process
// // requires webPreferences.nodeIntegration true and contextIsolation false
// await page.evaluate(() => {
// // eslint-disable-next-line @typescript-eslint/no-var-requires
// require('electron').ipcRenderer.send('new-window')
// })
// const newPage = await electronApp.waitForEvent('window')
// expect(newPage).toBeTruthy()
// expect(await newPage.title()).toBe('Window 4')
// page = newPage
// })

// test('receive IPC invoke/handle via renderer', async () => {
// // evaluate this script in RENDERER process and collect the result
// const result = await ipcRendererInvoke(page, 'how-many-windows')
// expect(result).toBe(4)
// })

// test('receive IPC handle data via main', async () => {
// // evaluate this script in MAIN process and collect the result
// const result = await ipcMainInvokeHandler(electronApp, 'openFiles')
// expect(result).toBe(4)
// })

// test('receive synchronous data via ipcRendererCallFirstListener()', async () => {
// const data = await ipcRendererCallFirstListener(page, 'get-synchronous-data')
// expect(data).toBe('Synchronous Data')
// })

// test('receive asynchronous data via ipcRendererCallFirstListener()', async () => {
// const data = await ipcRendererCallFirstListener(page, 'get-asynchronous-data')
// expect(data).toBe('Asynchronous Data')
// })

// test('receive synchronous data via ipcMainCallFirstListener()', async () => {
// const data = await ipcMainCallFirstListener(electronApp, 'main-synchronous-data')
// expect(data).toBe('Main Synchronous Data')
// })

// test('receive asynchronous data via ipcMainCallFirstListener()', async () => {
// const data = await ipcMainCallFirstListener(electronApp, 'main-asynchronous-data')
// expect(data).toBe('Main Asynchronous Data')
// })

// test('select a menu item via the main process', async () => {
// await clickMenuItemById(electronApp, 'new-window')
// const newPage = await electronApp.waitForEvent('window')
// expect(newPage).toBeTruthy()
// expect(await newPage.title()).toBe('Window 5')
// page = newPage
// })

test('make sure two screenshots of the same page match', async () => {
// take a screenshot of the current page
const screenshot1: Buffer = await page.screenshot()
// create a visual hash using Jimp
const screenshot1hash = (await jimp.read(screenshot1)).hash()
// take a screenshot of the page
const screenshot2: Buffer = await page.screenshot()
// create a visual hash using Jimp
const screenshot2hash = (await jimp.read(screenshot2)).hash()
// compare the two hashes
expect(screenshot1hash).toEqual(screenshot2hash)
})

0 comments on commit 2f10efc

Please sign in to comment.