Skip to content

Commit ed603a9

Browse files
committed
fix: fix some tests
1 parent 4d2509a commit ed603a9

File tree

17 files changed

+480
-126
lines changed

17 files changed

+480
-126
lines changed

jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export default {
22
transform: {
33
'^.+\\.(js|jsx)?$': 'babel-jest',
44
},
5+
testPathIgnorePatterns: ['/node_modules/', '/examples/'],
56
testEnvironment: 'node',
67
};

lib/constants/messages/env.messages.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ const env = {
1010
success: {},
1111
info: {},
1212
errors: {
13-
invalid_environment: 'Invalid environment. Please set ENV to either production, stage, or local.',
13+
invalid_environment:
14+
'Invalid environment. Please set ENV to either production, stage, or local.',
1415
},
1516
runtime: {
1617
success: {},
1718
info: {},
1819
errors: {
1920
unknown_error: 'An error occurred while executing the script',
2021
fetch_event_missing: 'No fetch event handler was defined',
21-
fetch_event_unknown_error: 'An error occurred while handling the fetch event:',
22+
fetch_event_unknown_error:
23+
'An error occurred while handling the fetch event:',
2224
fetch_event_remove_listener: 'Unable to remove event listener.',
2325
fetch_event_type: (type) => `Unsupported event type: ${type}`,
2426
undefined_response: 'No response was defined',

lib/main.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { resolve } from 'path';
33
import { readFileSync } from 'fs';
44
import { Command } from 'commander';
55
import { satisfies } from 'semver';
6-
import {
7-
feedback, debug, getAbsoluteLibDirPath,
8-
} from '#utils';
6+
import { feedback, debug, getAbsoluteLibDirPath } from '#utils';
97
import { Messages } from '#constants';
108

119
const MIN_NODE_VERSION = '18.0.0';
1210

1311
const vulcanLibPath = getAbsoluteLibDirPath();
1412
const vulcanRootPath = resolve(vulcanLibPath, '..');
15-
const vulcanPackageJSON = JSON.parse(readFileSync(`${vulcanRootPath}/package.json`, 'utf8'));
13+
const vulcanPackageJSON = JSON.parse(
14+
readFileSync(`${vulcanRootPath}/package.json`, 'utf8'),
15+
);
1616
const vulcanVersion = vulcanPackageJSON.version;
1717

1818
const debugEnabled = process.env.DEBUG === 'true';
@@ -90,11 +90,7 @@ function startVulcanProgram() {
9090
'Mode of build target (e.g., deliver, compute)',
9191
'compute',
9292
)
93-
.option(
94-
'--useNodePolyfills',
95-
'Use node polyfills in build.',
96-
'false',
97-
)
93+
.option('--useNodePolyfills', 'Use node polyfills in build.', 'false')
9894
.action(async (options) => {
9995
const { buildCommand } = await import('#commands');
10096
await buildCommand(options);
@@ -112,8 +108,13 @@ function startVulcanProgram() {
112108

113109
program
114110
.command('presets <command>')
115-
.description('Create <create> or list <ls> defined project presets for Edge')
116-
.option('--preset <name>', 'Specify the name of the preset to list its modes')
111+
.description(
112+
'Create <create> or list <ls> defined project presets for Edge',
113+
)
114+
.option(
115+
'--preset <name>',
116+
'Specify the name of the preset to list its modes',
117+
)
117118
.action(async (command, options) => {
118119
const { presetsCommand } = await import('#commands');
119120
await presetsCommand(command, options.preset);
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
1-
import assert from 'assert';
2-
import { feedback } from '#utils';
1+
// import assert from 'assert';
2+
// import { feedback } from '#utils';
3+
import { describe, it } from '@jest/globals';
34
import mountSPA from './index.js';
45

56
/**
67
* Test the mountSPA function.
78
*/
8-
function testmountSPA() {
9-
const requestURL = 'https://example.com/path/to/resource';
10-
const versionId = 'v1';
11-
const expectedAssetUrl = 'file:///v1/path/to/resource';
9+
describe('mountSPA', () => {
10+
// Mock the fetch function before each test
11+
beforeEach(() => {
12+
global.fetch = jest.fn();
13+
});
1214

13-
const assetUrl = mountSPA(requestURL, versionId);
15+
// Restore the original fetch function after each test
16+
afterEach(() => {
17+
global.fetch.mockRestore();
18+
});
1419

15-
assert.strictEqual(assetUrl.href, expectedAssetUrl);
16-
feedback.success('mountSPA test passed!');
17-
}
20+
it('should construct the assetPath for assets correctly', () => {
21+
const requestURL = 'http://example.com/assets/image.png';
22+
const versionId = 'v1';
1823

19-
testmountSPA();
24+
const expectedAssetPath = new URL('/v1/assets/image.png', 'file://');
25+
26+
// Mock the fetch response
27+
global.fetch.mockResolvedValue({
28+
// Define the expected response here
29+
// For example, you can mock a Response object with status, json() method, etc.
30+
});
31+
32+
// Call your function and make assertions
33+
return mountSPA(requestURL, versionId).then(() => {
34+
// Add your assertions here
35+
expect(global.fetch).toHaveBeenCalledWith(expectedAssetPath);
36+
// Add more assertions based on your specific use case
37+
});
38+
});
39+
40+
// Add more test cases as needed
41+
});

lib/platform/services/base.service.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const APIS = {
1313
* @param {string} resource - The resource string to process.
1414
* @returns {string} The processed resource string without leading and trailing slashes.
1515
*/
16-
const removeLeadingAndTrailingSlashes = (resource) => (resource ? `/${resource.toString().replace(/^\/|\/$/g, '')}` : '');
16+
const removeLeadingAndTrailingSlashes = (resource) =>
17+
resource ? `/${resource.toString().replace(/^\/|\/$/g, '')}` : '';
1718

1819
/**
1920
* Reads the API token from the Vulcan environment.

0 commit comments

Comments
 (0)