Skip to content

Commit 313d0d3

Browse files
committed
feat: jestのセットアップファイルを追加し、URLモックを設定
fix: ESLint設定にreact/jsx-props-no-spreadingルールを追加 fix: テストワークフローをmacOS専用に変更 fix: DataPlotコンポーネントのインポートを整理 fix: DataViewerコンポーネントのレイアウト設定を修正
1 parent 1ed3bab commit 313d0d3

8 files changed

Lines changed: 62 additions & 22 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = {
2020
'consistent-return': 'off',
2121
'no-plusplus': 'off',
2222
'no-alert': 'off',
23+
'react/jsx-props-no-spreading': 'off',
2324
},
2425
parserOptions: {
2526
ecmaVersion: 2020,

.github/workflows/test.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ on: [push, pull_request, workflow_dispatch]
44

55
jobs:
66
test:
7-
runs-on: ${{ matrix.os }}
8-
9-
strategy:
10-
matrix:
11-
os: [macos-latest, windows-latest, ubuntu-latest]
7+
runs-on: macos-latest
128

139
steps:
1410
- name: Check out Git repository
@@ -35,5 +31,4 @@ jobs:
3531
run: |
3632
npm run package
3733
npm run lint
38-
npm exec tsc
3934
npm test

package-lock.json

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

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@
8181
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/.erb/mocks/fileMock.js",
8282
"\\.(css|less|sass|scss)$": "identity-obj-proxy"
8383
},
84+
"setupFilesAfterEnv": [
85+
"jest-canvas-mock",
86+
"<rootDir>/test/jest.setup.js"
87+
],
8488
"setupFiles": [
8589
"./.erb/scripts/check-build-exists.ts"
8690
],
@@ -163,6 +167,7 @@
163167
"html-webpack-plugin": "^5.5.1",
164168
"identity-obj-proxy": "^3.0.0",
165169
"jest": "^29.5.0",
170+
"jest-canvas-mock": "^2.5.2",
166171
"jest-environment-jsdom": "^29.5.0",
167172
"mini-css-extract-plugin": "^2.7.6",
168173
"prettier": "^2.8.8",

src/main/main.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint global-require: off, no-console: off, promise/always-return: off */
2-
/* global BrowserWindow */
32

4-
import type { BrowserWindow } from 'electron'; // Added this line
3+
import type { BrowserWindow, HandlerDetails } from 'electron'; // Added this line
54

65
/**
76
* This module executes inside of electron's main process. You can start
@@ -34,7 +33,8 @@ const {
3433
} = require('./electron-src/lib/serialManager');
3534
const { resolveHtmlPath } = require('./util');
3635

37-
const transpose = (a: string[][]): string[][] => a[0].map((_: string, c: number) => a.map((r: string[]) => r[c])); // Added types
36+
const transpose = (a: string[][]): string[][] =>
37+
a[0].map((_: string, c: number) => a.map((r: string[]) => r[c])); // Added types
3838

3939
class AppUpdater {
4040
constructor() {
@@ -86,7 +86,8 @@ const createWindow = async () => {
8686
return path.join(RESOURCES_PATH, ...paths);
8787
};
8888

89-
mainWindow = new ElectronBrowserWindow({ // Used ElectronBrowserWindow
89+
mainWindow = new ElectronBrowserWindow({
90+
// Used ElectronBrowserWindow
9091
title: 'Serial Plot Tools',
9192
show: false,
9293
width: 1024,
@@ -117,7 +118,8 @@ const createWindow = async () => {
117118
});
118119

119120
// Open urls in the user's browser
120-
mainWindow.webContents.setWindowOpenHandler((edata: Electron.HandlerDetails) => { // Added type for edata
121+
mainWindow.webContents.setWindowOpenHandler((edata: HandlerDetails) => {
122+
// Added type for edata
121123
shell.openExternal(edata.url);
122124
return { action: 'deny' };
123125
});
@@ -136,7 +138,8 @@ const createWindow = async () => {
136138
const primaryDisplay = screen.getPrimaryDisplay();
137139
const { width, height } = primaryDisplay.workAreaSize;
138140

139-
const newWindow = new ElectronBrowserWindow({ // Used ElectronBrowserWindow
141+
const newWindow = new ElectronBrowserWindow({
142+
// Used ElectronBrowserWindow
140143
title: 'Realtime Data Logger',
141144
width,
142145
height,
@@ -169,7 +172,8 @@ const createWindow = async () => {
169172
const primaryDisplay = screen.getPrimaryDisplay();
170173
const { width, height } = primaryDisplay.workAreaSize;
171174

172-
subWindowDataViewer = new ElectronBrowserWindow({ // Used ElectronBrowserWindow
175+
subWindowDataViewer = new ElectronBrowserWindow({
176+
// Used ElectronBrowserWindow
173177
title: 'Data Viewer',
174178
width,
175179
height,

src/renderer/components/DataPlot.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { Layout, ScatterData } from 'plotly.js';
12
import { useEffect, useRef, useState } from 'react';
23
import Plot from 'react-plotly.js';
3-
import { ScatterData, Layout } from 'plotly.js';
44
import './index.scss';
55

66
type DataType = {
@@ -40,7 +40,11 @@ class Line {
4040
this.revision = 0;
4141
}
4242

43-
update(lineData: Partial<ScatterData>, layout: Partial<Layout>, revision: number) {
43+
update(
44+
lineData: Partial<ScatterData>,
45+
layout: Partial<Layout>,
46+
revision: number
47+
) {
4448
this.lineData = lineData;
4549
this.layout = layout;
4650
this.revision = revision;
@@ -116,4 +120,4 @@ export default function DataViewer() {
116120
})}
117121
</>
118122
);
119-
}
123+
}

src/renderer/pages/DataViewer/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ export default function DataViewer() {
106106
},
107107
] as Data[]
108108
}
109-
layout={{
110-
xaxis: { title: '時刻' },
111-
yaxis: { title: data.title },
112-
title: '',
113-
margin: { t: 0 },
114-
} as Partial<Layout>}
109+
layout={
110+
{
111+
xaxis: { title: '時刻' },
112+
yaxis: { title: data.title },
113+
title: '',
114+
margin: { t: 0 },
115+
} as Partial<Layout>
116+
}
115117
/>
116118
);
117119
})}

test/jest.setup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// window.URL.createObjectURL と revokeObjectURL をモックする
2+
window.URL.createObjectURL = jest.fn();
3+
window.URL.revokeObjectURL = jest.fn();

0 commit comments

Comments
 (0)