mirror of
https://github.com/flarum/core.git
synced 2025-08-05 07:57:46 +02:00
feat: export registry (#3842)
* feat: registry first iteration Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * feat: improve webpack auto export loader Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * chore: remove `compat` API Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * chore: cleanup Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> --------- Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
54
js-packages/webpack-config/tests/autoExportLoader.test.js
Normal file
54
js-packages/webpack-config/tests/autoExportLoader.test.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @jest-environment node
|
||||
*/
|
||||
import compiler from './compiler.js';
|
||||
import 'regenerator-runtime/runtime';
|
||||
|
||||
const compile = async (path, useFinalOutput = false) => {
|
||||
const stats = await compiler(path);
|
||||
return useFinalOutput
|
||||
? stats.finalOutput
|
||||
: stats.toJson({
|
||||
source: true,
|
||||
}).modules[0].source;
|
||||
};
|
||||
|
||||
test('A directory with index.js that exports multiple modules adds the directory as a module', async () => {
|
||||
let output = await compile('src/common/bars/index.js', true);
|
||||
expect(output).toContain("flarum.reg.add('flarum-framework', 'common/bars', bars)");
|
||||
|
||||
output = await compile('src/common/bars/Acme.js');
|
||||
expect(output).toContain("flarum.reg.add('flarum-framework', 'common/bars/Acme', Acme)");
|
||||
|
||||
output = await compile('src/common/bars/Foo.js');
|
||||
expect(output).toContain("flarum.reg.add('flarum-framework', 'common/bars/Foo', Foo)");
|
||||
});
|
||||
|
||||
test('Simple default exports are added', async () => {
|
||||
const output = await compile('src/common/Test.js');
|
||||
expect(output).toContain("flarum.reg.add('flarum-framework', 'common/Test', Test)");
|
||||
});
|
||||
|
||||
test('Named exports are added', async () => {
|
||||
const output = await compile('src/common/foos/namedExports.js');
|
||||
expect(output).toContain(
|
||||
"flarum.reg.add('flarum-framework', 'common/foos/namedExports', { baz: baz,foo: foo,Bar: Bar,sasha: sasha,flarum: flarum,david: david, })"
|
||||
);
|
||||
});
|
||||
|
||||
test('Export as default from another module is added', async () => {
|
||||
const output = await compile('src/common/foos/exportDefaultFrom.js', true);
|
||||
expect(output).toContain("flarum.reg.add('flarum-framework', 'common/foos/exportDefaultFrom', potato");
|
||||
});
|
||||
|
||||
test('Export from other modules is added', async () => {
|
||||
const output = await compile('src/common/foos/exportFrom.js', true);
|
||||
expect(output).toContain("flarum.reg.add('flarum-framework', 'common/foos/exportFrom', { potato: potato,franz: franz, }");
|
||||
});
|
||||
|
||||
test('Export from with other named exports works', async () => {
|
||||
const output = await compile('src/common/foos/exportFromWithNamedExports.js', true);
|
||||
expect(output).toContain(
|
||||
"flarum.reg.add('flarum-framework', 'common/foos/exportFromWithNamedExports', { potato: potato,franz: franz,baz: baz,foo: foo,Bar: Bar,sasha: sasha,forum: forum,david: david, }"
|
||||
);
|
||||
});
|
Reference in New Issue
Block a user