diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8fa1209..1e91862 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -153,4 +153,4 @@ jobs: - name: Build Desktop if: runner.os != 'Windows' run: | - make desktop-package desktop-make + make desktop-package desktop-make desktop-test diff --git a/.gitignore b/.gitignore index c52d8e3..11f2cc8 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ console/atest-desktop/out console/atest-desktop/node_modules console/atest-desktop/atest console/atest-desktop/atest.exe +console/atest-desktop/coverage diff --git a/console/atest-desktop/api.js b/console/atest-desktop/api.js index 5defb82..0dd6f62 100644 --- a/console/atest-desktop/api.js +++ b/console/atest-desktop/api.js @@ -1,5 +1,23 @@ +/* +Copyright 2024 API Testing Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +const path = require('node:path') + exports.control = function(okCallback, errorCallback) { - fetch('http://localhost:' + getPort() + '/healthz'). + fetch(getHealthzUrl()). then(okCallback).catch(errorCallback) } @@ -12,5 +30,21 @@ function getHomePage() { return 'http://localhost:' + getPort() } +function getHealthzUrl() { + return 'http://localhost:' + getPort() + '/healthz' +} + +function getHomeDir() { + const homedir = require('os').homedir(); + return path.join(homedir, ".config", 'atest') +} + +function getLogfile() { + return path.join(getHomeDir(), 'log.log') +} + exports.getPort = getPort exports.getHomePage = getHomePage +exports.getHomeDir = getHomeDir +exports.getLogfile = getLogfile +exports.getHealthzUrl = getHealthzUrl diff --git a/console/atest-desktop/api.test.js b/console/atest-desktop/api.test.js new file mode 100644 index 0000000..85fa1ba --- /dev/null +++ b/console/atest-desktop/api.test.js @@ -0,0 +1,22 @@ +const { getPort, getHealthzUrl, getHomePage } = require('./api'); + +describe('getPort function', () => { + test('should return the default port number 7788', () => { + const port = getPort(); + expect(port).toBe(7788); + }); +}); + +describe('getHealthzUrl function', () => { + test('should return the default healthz url', () => { + const url = getHealthzUrl(); + expect(url).toBe('http://localhost:7788/healthz'); + }); +}); + +describe('getHomePage function', () => { + test('should return the default home page url', () => { + const url = getHomePage(); + expect(url).toBe('http://localhost:7788'); + }); +}) diff --git a/console/atest-desktop/forge.config.js b/console/atest-desktop/forge.config.js index a59f301..12d6ea6 100644 --- a/console/atest-desktop/forge.config.js +++ b/console/atest-desktop/forge.config.js @@ -1,3 +1,19 @@ +/* +Copyright 2024 API Testing Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + const { FusesPlugin } = require('@electron-forge/plugin-fuses'); const { FuseV1Options, FuseVersion } = require('@electron/fuses'); const path = require('node:path'); diff --git a/console/atest-desktop/index.html b/console/atest-desktop/index.html index fa45cd7..b7f675e 100644 --- a/console/atest-desktop/index.html +++ b/console/atest-desktop/index.html @@ -9,35 +9,63 @@
- -