Skip to content

Commit c1f58ad

Browse files
chore(runtime): fix typos in tests (#3033)
1 parent 9fa68f7 commit c1f58ad

File tree

10 files changed

+106
-190
lines changed

10 files changed

+106
-190
lines changed

packages/runtime/__tests__/api.spec.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import { describe, it } from 'vitest';
1+
import { describe, it, expect } from 'vitest';
22
import { init } from '../src';
33

44
// eslint-disable-next-line max-lines-per-function
55
describe('api', () => {
6-
it('apis', () => {
6+
it('initializes and validates API structure', () => {
77
const FM = init({
88
name: '@federation/name',
99
remotes: [],
1010
});
1111
expect(FM.loadShare).not.toBe(null);
1212
expect(FM.loadRemote).not.toBe(null);
1313
});
14-
15-
it('init with same name', () => {
16-
// get same instance
14+
it('initializes with the same name and returns the same instance', () => {
1715
const FM1 = init({
1816
name: '@federation/same-name',
1917
remotes: [],
@@ -24,9 +22,7 @@ describe('api', () => {
2422
});
2523
expect(FM1).toBe(FM2);
2624
});
27-
28-
it('init with same name with diffrent version', () => {
29-
// get same instance
25+
it('initializes with the same name but different versions and returns different instances', () => {
3026
const FM1 = init({
3127
name: '@federation/same-name-with-version',
3228
version: '1.0.1',
@@ -39,9 +35,7 @@ describe('api', () => {
3935
});
4036
expect(FM1).not.toBe(FM2);
4137
});
42-
43-
it('init merge remotes', () => {
44-
// get same instance
38+
it('merges remotes when initialized with the same name', () => {
4539
const FM1 = init({
4640
name: '@federation/merge-remotes',
4741
remotes: [
@@ -78,9 +72,7 @@ describe('api', () => {
7872
]),
7973
);
8074
});
81-
82-
it('init with diffrent same name', () => {
83-
// get different instance
75+
it('initializes with different names and returns different instances', () => {
8476
const FM3 = init({
8577
name: '@federation/main3',
8678
remotes: [],

packages/runtime/__tests__/globa.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert, describe, test, it, vi } from 'vitest';
1+
import { describe, it, expect, vi } from 'vitest';
22
import { init } from '../src/index';
33

44
describe('global', () => {

packages/runtime/__tests__/global.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { assert, describe, test, it, vi, expectTypeOf } from 'vitest';
1+
import { expectTypeOf, describe, it, vi, expect } from 'vitest';
22
import { init, loadRemote, loadShare, loadShareSync } from '../src/index';
33
import { getInfoWithoutType } from '../src/global';
44

55
describe('global', () => {
66
it('inject mode', () => {
7-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = vi.fn() as any;
7+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = vi.fn();
88
const injectArgs = {
99
name: '@federation/inject-mode',
1010
remotes: [],
@@ -64,7 +64,7 @@ describe('global', () => {
6464
>();
6565
});
6666

67-
it('loadShareSync', async () => {
67+
it('loadShareSync', () => {
6868
const typedLoadShareSync: typeof loadShareSync<string> = loadShareSync;
6969
expectTypeOf(typedLoadShareSync).returns.toMatchTypeOf<
7070
() => string | never

packages/runtime/__tests__/hooks.spec.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ describe('hooks', () => {
7979
expect(initArgs.options.plugins).toEqual(
8080
expect.arrayContaining(options.plugins),
8181
);
82-
83-
// modify ./sub expose to ./add
82+
// Modify ./sub to expose ./add
8483
const module =
8584
await GM.loadRemote<(...args: Array<number>) => number>('@demo/main/sub');
8685
assert(module, 'loadRemote should return a module');
@@ -235,20 +234,14 @@ describe('hooks', () => {
235234
statusText: 'OK',
236235
headers: { 'Content-Type': 'application/json' },
237236
});
238-
239-
const fetchPlugin: () => FederationRuntimePlugin = function () {
240-
return {
241-
name: 'fetch-plugin',
242-
fetch(url, options) {
243-
if (
244-
url === 'http://mockxxx.com/loader-fetch-hooks-mf-manifest.json'
245-
) {
246-
return Promise.resolve(responseBody);
247-
}
248-
},
249-
};
250-
};
251-
237+
const fetchPlugin: () => FederationRuntimePlugin = () => ({
238+
name: 'fetch-plugin',
239+
fetch(url, options) {
240+
if (url === 'http://mockxxx.com/loader-fetch-hooks-mf-manifest.json') {
241+
return Promise.resolve(responseBody);
242+
}
243+
},
244+
});
252245
const INSTANCE = new FederationHost({
253246
name: '@loader-hooks/fetch',
254247
remotes: [

packages/runtime/__tests__/instance.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert, describe, test, it } from 'vitest';
22
import { FederationHost } from '../src/index';
33

44
describe('FederationHost', () => {
5-
it('args', () => {
5+
it('should initialize with provided arguments', () => {
66
const GM = new FederationHost({
77
name: '@federation/instance',
88
version: '1.0.1',
Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
1-
import { assert, describe, test, it } from 'vitest';
1+
import { describe, it, expect } from 'vitest';
22
import { isStaticResourcesEqual } from '../src/utils/tool';
3-
// eslint-disable-next-line max-lines-per-function
43
describe('isStaticResourcesEqual', () => {
5-
it('check resources while url not specify protocol', () => {
4+
it('verify resources when URL does not specify protocol', () => {
65
const url = '//a.b.c';
7-
const sc = document.createElement('script');
8-
sc.src = url;
9-
expect(sc.src).toBe('http://a.b.c/');
10-
11-
expect(isStaticResourcesEqual(sc.src, url)).toBe(true);
12-
expect(isStaticResourcesEqual(sc.src, 'http://a.b.c/')).toBe(true);
13-
expect(isStaticResourcesEqual(sc.src, 'http://a.b.c')).toBe(true);
6+
const scriptElement = document.createElement('script');
7+
scriptElement.src = url;
8+
expect(scriptElement.src).toBe('http://a.b.c/');
9+
expect(isStaticResourcesEqual(scriptElement.src, url)).toBe(true);
10+
expect(isStaticResourcesEqual(scriptElement.src, 'http://a.b.c/')).toBe(
11+
true,
12+
);
13+
expect(isStaticResourcesEqual(scriptElement.src, 'http://a.b.c')).toBe(
14+
true,
15+
);
1416
});
15-
16-
it('check resources while url specify protocol(https)', () => {
17+
it('verify resources when URL specifies protocol (https)', () => {
1718
const url = 'https://a.b.c';
18-
const sc = document.createElement('script');
19-
sc.src = url;
20-
expect(sc.src).toBe('https://a.b.c/');
21-
22-
expect(isStaticResourcesEqual(sc.src, url)).toBe(true);
23-
expect(isStaticResourcesEqual(sc.src, 'https://a.b.c/')).toBe(true);
24-
expect(isStaticResourcesEqual(sc.src, '//a.b.c')).toBe(true);
25-
expect(isStaticResourcesEqual(sc.src, 'a.b.c')).toBe(true);
26-
27-
expect(isStaticResourcesEqual(sc.src, 'http://a.b.c')).toBe(true);
19+
const scriptElement = document.createElement('script');
20+
scriptElement.src = url;
21+
expect(scriptElement.src).toBe('https://a.b.c/');
22+
expect(isStaticResourcesEqual(scriptElement.src, url)).toBe(true);
23+
expect(isStaticResourcesEqual(scriptElement.src, 'https://a.b.c/')).toBe(
24+
true,
25+
);
26+
expect(isStaticResourcesEqual(scriptElement.src, '//a.b.c')).toBe(true);
27+
expect(isStaticResourcesEqual(scriptElement.src, 'a.b.c')).toBe(true);
28+
expect(isStaticResourcesEqual(scriptElement.src, 'http://a.b.c')).toBe(
29+
true,
30+
);
2831
});
29-
30-
it('check resources while url specify protocol(http)', () => {
32+
it('verify resources when URL specifies protocol (http)', () => {
3133
const url = 'http://a.b.c';
32-
const sc = document.createElement('script');
33-
sc.src = url;
34-
expect(sc.src).toBe('http://a.b.c/');
35-
36-
expect(isStaticResourcesEqual(sc.src, url)).toBe(true);
37-
expect(isStaticResourcesEqual(sc.src, 'http://a.b.c/')).toBe(true);
38-
expect(isStaticResourcesEqual(sc.src, '//a.b.c')).toBe(true);
39-
expect(isStaticResourcesEqual(sc.src, 'a.b.c')).toBe(true);
40-
41-
expect(isStaticResourcesEqual(sc.src, 'https://a.b.c')).toBe(true);
34+
const scriptElement = document.createElement('script');
35+
scriptElement.src = url;
36+
expect(scriptElement.src).toBe('http://a.b.c/');
37+
expect(isStaticResourcesEqual(scriptElement.src, url)).toBe(true);
38+
expect(isStaticResourcesEqual(scriptElement.src, 'http://a.b.c/')).toBe(
39+
true,
40+
);
41+
expect(isStaticResourcesEqual(scriptElement.src, '//a.b.c')).toBe(true);
42+
expect(isStaticResourcesEqual(scriptElement.src, 'a.b.c')).toBe(true);
43+
expect(isStaticResourcesEqual(scriptElement.src, 'https://a.b.c')).toBe(
44+
true,
45+
);
4246
});
4347
});

packages/runtime/__tests__/load-remote.spec.ts

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { requestList } from './mock/env';
1313

1414
describe('matchRemote', () => {
15-
it('match default export with pkgName', () => {
15+
it('matches default export with pkgName', () => {
1616
const matchInfo = matchRemoteWithNameAndExpose(
1717
[
1818
{
@@ -34,8 +34,7 @@ describe('matchRemote', () => {
3434
version: '1.0.0',
3535
});
3636
});
37-
38-
it('match default export with alias', () => {
37+
it('matches default export with alias', () => {
3938
const matchInfo = matchRemoteWithNameAndExpose(
4039
[
4140
{
@@ -59,8 +58,7 @@ describe('matchRemote', () => {
5958
alias: 'hello',
6059
});
6160
});
62-
63-
it('match pkgName', () => {
61+
it('matches pkgName', () => {
6462
const matchInfo = matchRemoteWithNameAndExpose(
6563
[
6664
{
@@ -82,8 +80,7 @@ describe('matchRemote', () => {
8280
version: '1.0.0',
8381
});
8482
});
85-
86-
it('match alias', () => {
83+
it('matches alias', () => {
8784
const matchInfo = matchRemoteWithNameAndExpose(
8885
[
8986
{
@@ -111,7 +108,7 @@ describe('matchRemote', () => {
111108

112109
// eslint-disable-next-line max-lines-per-function
113110
describe('loadRemote', () => {
114-
it('api', () => {
111+
it('api functionality', () => {
115112
const FederationInstance = new FederationHost({
116113
name: '@federation-test/loadRemote-api',
117114
remotes: [],
@@ -221,8 +218,7 @@ describe('loadRemote', () => {
221218
expect(module2()).toBe('hello app2');
222219
reset();
223220
});
224-
225-
it('compatible with old structor', async () => {
221+
it('is compatible with old structure', async () => {
226222
const reset = addGlobalSnapshot({
227223
'@federation-test/compatible': {
228224
globalName: '',
@@ -271,8 +267,7 @@ describe('loadRemote', () => {
271267
expect(module()).toBe('hello app2');
272268
reset();
273269
});
274-
275-
it('remote entry url with query', async () => {
270+
it('handles remote entry URL with query', async () => {
276271
const FederationInstance = new FederationHost({
277272
name: '@federation-test/compatible',
278273
remotes: [
@@ -289,8 +284,7 @@ describe('loadRemote', () => {
289284
assert(module, 'module should be a function');
290285
expect(module()).toBe('hello app2');
291286
});
292-
293-
it('different instance with same module', async () => {
287+
it('handles different instances with the same module', async () => {
294288
const reset = addGlobalSnapshot({
295289
'@module-federation/load-remote-different-instance': {
296290
buildVersion: 'custom',
@@ -360,7 +354,7 @@ describe('loadRemote', () => {
360354
});
361355

362356
describe('loadRemote with manifest.json', () => {
363-
it('duplicate request manifest.json', async () => {
357+
it('handles duplicate request to manifest.json', async () => {
364358
const FM = new FederationHost({
365359
name: '@demo/host',
366360
remotes: [
@@ -398,8 +392,7 @@ describe('loadRemote with manifest.json', () => {
398392
),
399393
).toBe(1);
400394
});
401-
402-
it('circulate deps', async () => {
395+
it('handles circular dependencies', async () => {
403396
setGlobalFederationConstructor(FederationHost, true);
404397
const FM = init({
405398
name: '@circulate-deps/app1',
@@ -422,8 +415,7 @@ describe('loadRemote with manifest.json', () => {
422415
Global.__FEDERATION__.__INSTANCES__ = [];
423416
setGlobalFederationConstructor(undefined, true);
424417
});
425-
426-
it('manifest.json with query', async () => {
418+
it('handles manifest.json with query', async () => {
427419
const FM = new FederationHost({
428420
name: '@demo/host',
429421
remotes: [
@@ -442,9 +434,8 @@ describe('loadRemote with manifest.json', () => {
442434
expect(module()).toBe('hello world');
443435
});
444436
});
445-
446-
describe('lazy loadRemote add remote into snapshot', () => {
447-
it('load remoteEntry', async () => {
437+
describe('lazy loadRemote and add remote into snapshot', () => {
438+
it('loads remoteEntry', async () => {
448439
const reset = addGlobalSnapshot({
449440
'@demo/app2': {
450441
buildVersion: '1.0.2',
@@ -498,8 +489,7 @@ describe('lazy loadRemote add remote into snapshot', () => {
498489
expect(afterRemotesLength).toBe(1);
499490
reset();
500491
});
501-
502-
it('load manifest', async () => {
492+
it('loads manifest', async () => {
503493
const reset = addGlobalSnapshot({
504494
'@demo/app1': {
505495
globalName: `__FEDERATION_${'@load-remote/app1:custom'}__`,
@@ -545,7 +535,7 @@ describe('lazy loadRemote add remote into snapshot', () => {
545535
});
546536

547537
describe('loadRemote', () => {
548-
it('api', async () => {
538+
it('loads remote synchronously', async () => {
549539
const jsSyncAssetPath = 'resources/load-remote/app2/say.sync.js';
550540
const remotePublicPath = 'http://localhost:1111/';
551541
const reset = addGlobalSnapshot({

0 commit comments

Comments
 (0)