aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/infrastructure/electron
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-05-09 01:37:06 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-05-16 00:55:03 +0200
commita6fade92974dbba63a7d7a07f80bb447dfdf4f5b (patch)
tree8c7dfc3cc4a041412cc6be9a260acc8238b78013 /packages/main/src/infrastructure/electron
parenttest: prefer jest API instead of jest-each (diff)
downloadsophie-a6fade92974dbba63a7d7a07f80bb447dfdf4f5b.tar.gz
sophie-a6fade92974dbba63a7d7a07f80bb447dfdf4f5b.tar.zst
sophie-a6fade92974dbba63a7d7a07f80bb447dfdf4f5b.zip
test: use test instead of it
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/infrastructure/electron')
-rw-r--r--packages/main/src/infrastructure/electron/impl/__tests__/electron.integ.test.ts (renamed from packages/main/src/infrastructure/electron/impl/__tests__/electron.integ.spec.ts)2
-rw-r--r--packages/main/src/infrastructure/electron/impl/__tests__/hardenSession.test.ts (renamed from packages/main/src/infrastructure/electron/impl/__tests__/hardenSession.spec.ts)8
-rw-r--r--packages/main/src/infrastructure/electron/impl/__tests__/lockWebContentsToFile.test.ts (renamed from packages/main/src/infrastructure/electron/impl/__tests__/lockWebContentsToFile.spec.ts)20
3 files changed, 15 insertions, 15 deletions
diff --git a/packages/main/src/infrastructure/electron/impl/__tests__/electron.integ.spec.ts b/packages/main/src/infrastructure/electron/impl/__tests__/electron.integ.test.ts
index f6bd440..67cf689 100644
--- a/packages/main/src/infrastructure/electron/impl/__tests__/electron.integ.spec.ts
+++ b/packages/main/src/infrastructure/electron/impl/__tests__/electron.integ.test.ts
@@ -2,7 +2,7 @@ import { BrowserWindow } from 'electron';
2 2
3import '../ElectronMainWindow'; 3import '../ElectronMainWindow';
4 4
5it('should create a BrowserWindow', async () => { 5test('create a BrowserWindow', async () => {
6 const w = new BrowserWindow(); 6 const w = new BrowserWindow();
7 await expect(w.loadURL('https://example.org')).resolves.toBeUndefined(); 7 await expect(w.loadURL('https://example.org')).resolves.toBeUndefined();
8 w.close(); 8 w.close();
diff --git a/packages/main/src/infrastructure/electron/impl/__tests__/hardenSession.spec.ts b/packages/main/src/infrastructure/electron/impl/__tests__/hardenSession.test.ts
index dc15d68..7b70d10 100644
--- a/packages/main/src/infrastructure/electron/impl/__tests__/hardenSession.spec.ts
+++ b/packages/main/src/infrastructure/electron/impl/__tests__/hardenSession.test.ts
@@ -94,14 +94,14 @@ beforeEach(() => {
94 onBeforeRequest = undefined; 94 onBeforeRequest = undefined;
95}); 95});
96 96
97it('should set permission request and before request handlers', () => { 97test('set permission request and before request handlers', () => {
98 hardenSession(getFakeResources(false), false, fakeSession); 98 hardenSession(getFakeResources(false), false, fakeSession);
99 expect(permissionRequestHandler).toBeDefined(); 99 expect(permissionRequestHandler).toBeDefined();
100 expect(onBeforeRequest).toBeDefined(); 100 expect(onBeforeRequest).toBeDefined();
101}); 101});
102 102
103it.each(permissions.map((permission) => [permission]))( 103test.each(permissions.map((permission) => [permission]))(
104 'should reject %s permission requests', 104 'reject %s permission requests',
105 (permission: Permission) => { 105 (permission: Permission) => {
106 hardenSession(getFakeResources(false), false, fakeSession); 106 hardenSession(getFakeResources(false), false, fakeSession);
107 const callback = jest.fn(); 107 const callback = jest.fn();
@@ -114,7 +114,7 @@ it.each(permissions.map((permission) => [permission]))(
114 }, 114 },
115); 115);
116 116
117it.each([ 117test.each([
118 [ 118 [
119 false, 119 false,
120 'GET', 120 'GET',
diff --git a/packages/main/src/infrastructure/electron/impl/__tests__/lockWebContentsToFile.spec.ts b/packages/main/src/infrastructure/electron/impl/__tests__/lockWebContentsToFile.test.ts
index c9aeaab..47525d3 100644
--- a/packages/main/src/infrastructure/electron/impl/__tests__/lockWebContentsToFile.spec.ts
+++ b/packages/main/src/infrastructure/electron/impl/__tests__/lockWebContentsToFile.test.ts
@@ -12,7 +12,7 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details. 13 * GNU Affero General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Affero General Public License 15 * You have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 * 17 *
18 * SPDX-License-Identifier: AGPL-3.0-only 18 * SPDX-License-Identifier: AGPL-3.0-only
@@ -85,16 +85,16 @@ describe('when loadURL does not throw', () => {
85 await lockWebContentsToFile(fakeResources, 'index.html', fakeWebContents); 85 await lockWebContentsToFile(fakeResources, 'index.html', fakeWebContents);
86 }); 86 });
87 87
88 it('should load the specified file', () => { 88 test('loads the specified file', () => {
89 expect(fakeWebContents.loadURL).toHaveBeenCalledWith(urlToLoad); 89 expect(fakeWebContents.loadURL).toHaveBeenCalledWith(urlToLoad);
90 }); 90 });
91 91
92 it('should set up will navigate and window open listeners', () => { 92 test('sets up will navigate and window open listeners', () => {
93 expect(willNavigate).toBeDefined(); 93 expect(willNavigate).toBeDefined();
94 expect(windowOpenHandler).toBeDefined(); 94 expect(windowOpenHandler).toBeDefined();
95 }); 95 });
96 96
97 it('should prevent opening a window', () => { 97 test('prevents opening a window', () => {
98 const { action } = windowOpenHandler!({ 98 const { action } = windowOpenHandler!({
99 url: 'https://example.com', 99 url: 'https://example.com',
100 frameName: 'newWindow', 100 frameName: 'newWindow',
@@ -108,12 +108,12 @@ describe('when loadURL does not throw', () => {
108 expect(action).toBe('deny'); 108 expect(action).toBe('deny');
109 }); 109 });
110 110
111 it('should allow navigation to the loaded URL', () => { 111 test('allows navigation to the loaded URL', () => {
112 willNavigate!(event, urlToLoad); 112 willNavigate!(event, urlToLoad);
113 expect(event.preventDefault).not.toHaveBeenCalled(); 113 expect(event.preventDefault).not.toHaveBeenCalled();
114 }); 114 });
115 115
116 it('should not allow navigation to another URL', () => { 116 test('does not allow navigation to another URL', () => {
117 willNavigate!( 117 willNavigate!(
118 event, 118 event,
119 'file:///opt/sophie/resources/app.asar/packages/renderer/not-allowed.html', 119 'file:///opt/sophie/resources/app.asar/packages/renderer/not-allowed.html',
@@ -132,7 +132,7 @@ describe('when loadURL throws', () => {
132 describe('when the URL points at a file', () => { 132 describe('when the URL points at a file', () => {
133 const fakeResources = createFakeResources('http://localhost:3000'); 133 const fakeResources = createFakeResources('http://localhost:3000');
134 134
135 it('should swallow ERR_ABORTED errors', async () => { 135 test('swallows ERR_ABORTED errors', async () => {
136 const error = createAbortedError(); 136 const error = createAbortedError();
137 mocked(fakeWebContents.loadURL).mockRejectedValueOnce(error); 137 mocked(fakeWebContents.loadURL).mockRejectedValueOnce(error);
138 await expect( 138 await expect(
@@ -140,7 +140,7 @@ describe('when loadURL throws', () => {
140 ).resolves.not.toThrow(); 140 ).resolves.not.toThrow();
141 }); 141 });
142 142
143 it('should pass through other errors', async () => { 143 test('passes through other errors', async () => {
144 mocked(fakeWebContents.loadURL).mockRejectedValueOnce( 144 mocked(fakeWebContents.loadURL).mockRejectedValueOnce(
145 new Error('other error'), 145 new Error('other error'),
146 ); 146 );
@@ -153,7 +153,7 @@ describe('when loadURL throws', () => {
153 describe('when the URL points at a local server', () => { 153 describe('when the URL points at a local server', () => {
154 const fakeResources = createFakeResources(filePrefix); 154 const fakeResources = createFakeResources(filePrefix);
155 155
156 it('should pass through ERR_ABORTED errors', async () => { 156 test('passes through ERR_ABORTED errors', async () => {
157 const error = createAbortedError(); 157 const error = createAbortedError();
158 mocked(fakeWebContents.loadURL).mockRejectedValueOnce(error); 158 mocked(fakeWebContents.loadURL).mockRejectedValueOnce(error);
159 await expect( 159 await expect(
@@ -161,7 +161,7 @@ describe('when loadURL throws', () => {
161 ).rejects.toBeInstanceOf(Error); 161 ).rejects.toBeInstanceOf(Error);
162 }); 162 });
163 163
164 it('should pass through other errors', async () => { 164 test('passes through other errors', async () => {
165 mocked(fakeWebContents.loadURL).mockRejectedValueOnce( 165 mocked(fakeWebContents.loadURL).mockRejectedValueOnce(
166 new Error('other error'), 166 new Error('other error'),
167 ); 167 );