Skip to content

Commit b794831

Browse files
feat(enhanced): add filter test
1 parent eee661a commit b794831

File tree

2 files changed

+32
-89
lines changed

2 files changed

+32
-89
lines changed
Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,35 @@
1-
const { expect } = require('expect');
2-
3-
describe('prefix-share-filter', () => {
4-
let warnings;
5-
let oldWarn;
6-
7-
beforeEach(() => {
8-
warnings = [];
9-
oldWarn = console.warn;
10-
console.warn = (warning) => {
11-
warnings.push(warning);
12-
};
13-
});
14-
15-
afterEach(() => {
16-
console.warn = oldWarn;
17-
});
18-
19-
it('should share modules matching the filter pattern', async () => {
20-
const moduleA = await import('prefix/deep/module-a');
21-
expect(moduleA.default).toBe('module-a');
22-
23-
// This should be shared due to filter pattern
24-
const container = __webpack_require__.S['default'];
25-
expect(container).toBeDefined();
26-
expect(container['prefix/deep/module-a']).toBeDefined();
27-
});
1+
let warnings;
2+
let oldWarn;
3+
4+
beforeEach(() => {
5+
warnings = [];
6+
oldWarn = console.warn;
7+
console.warn = (warning) => {
8+
warnings.push(warning);
9+
};
10+
});
2811

29-
it('should not share modules not matching the filter pattern', async () => {
30-
const moduleB = await import('prefix/shallow-module');
31-
expect(moduleB.default).toBe('shallow-module');
12+
afterEach(() => {
13+
console.warn = oldWarn;
14+
});
3215

33-
// This should not be shared due to filter pattern
34-
const container = __webpack_require__.S['default'];
35-
expect(container['prefix/shallow-module']).toBeUndefined();
36-
});
16+
it('should share modules NOT matching the filter', async () => {
17+
const moduleA = await import('prefix/a');
18+
expect(moduleA.default).toBe('a');
3719

38-
it('should properly handle nested deep modules', async () => {
39-
const moduleC = await import('prefix/deep/nested/module-c');
40-
expect(moduleC.default).toBe('module-c');
20+
// This should not be shared due to filter pattern
21+
const container = __webpack_share_scopes__['test-scope'];
22+
console.log(container);
4123

42-
const container = __webpack_require__.S['default'];
43-
expect(container['prefix/deep/nested/module-c']).toBeDefined();
44-
});
24+
expect(container).toBeDefined();
25+
expect(container['prefix/a']).toBeDefined();
26+
});
4527

46-
it('should maintain module integrity when sharing', async () => {
47-
const moduleA1 = await import('prefix/deep/module-a');
48-
const moduleA2 = await import('prefix/deep/module-a');
28+
it('should not share modules in deep directory', async () => {
29+
const moduleB = await import('prefix/deep/b');
30+
expect(moduleB.default).toBe('b');
4931

50-
// Should be the same instance due to sharing
51-
expect(moduleA1).toBe(moduleA2);
52-
});
32+
// This should not be shared due to filter pattern
33+
const container = __webpack_require__.S['test-scope'];
34+
expect(container['prefix/deep/b']).toBeUndefined();
5335
});

packages/enhanced/test/configCases/sharing/prefix-share-filter/webpack.config.js

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,10 @@ module.exports = {
99
shared: {
1010
package: {},
1111
'@scoped/package': {},
12-
'prefix/': {},
13-
'./relative1': {},
14-
'./relative2': {},
15-
'advanced/': {
16-
import: false,
17-
requiredVersion: '^1.2.3',
18-
shareScope: 'other-scope',
19-
strictVersion: true,
20-
singleton: false,
21-
},
22-
strict0: {
23-
requiredVersion: '^1.0.0',
24-
strictVersion: true,
25-
},
26-
strict1: {
27-
requiredVersion: '>=1.2.0',
28-
strictVersion: true,
29-
},
30-
strict2: {
31-
requiredVersion: '1.1.0',
32-
strictVersion: true,
33-
},
34-
strict3: {
35-
requiredVersion: '~1.0.0',
36-
strictVersion: true,
37-
},
38-
strict4: {
39-
requiredVersion: '^2.2.3',
40-
strictVersion: true,
41-
},
42-
strict5: {
43-
import: false,
44-
requiredVersion: 'alpha',
45-
strictVersion: true,
46-
},
47-
singleton: {
48-
requiredVersion: '1.1.0',
49-
singleton: true,
50-
strictVersion: false,
51-
},
52-
singletonWithoutVersion: {
53-
requiredVersion: false,
54-
singleton: true,
12+
'prefix/': {
13+
filter: {
14+
request: /deep/
15+
}
5516
},
5617
},
5718
}),

0 commit comments

Comments
 (0)