Skip to content

Commit

Permalink
test (labs/ssr): add tests for package exports resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed Oct 19, 2022
1 parent 8b0ad8f commit 2e13a38
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/labs/ssr/src/lib/module-loader.ts
Expand Up @@ -278,6 +278,7 @@ export const resolveSpecifier = async (
modules: ['node_modules'],
extensions: ['.js'],
mainFields: ['module', 'jsnext:main', 'main'],
conditionNames: ['node'],
});
return pathToFileURL(modulePath);
}
Expand Down
34 changes: 34 additions & 0 deletions packages/labs/ssr/src/test/lib/module-loader_test.ts
Expand Up @@ -53,4 +53,38 @@ test('loads a module with a built-in import', async () => {
assert.ok(module.namespace.join);
});

test('resolves an exact exported path', async () => {
const loader = new ModuleLoader({global: window});
const result = await loader.importModule('./lit-import.js', testIndex);
const {module, path: modulePath} = result;
assert.is(module.namespace.litIsServer, true);
assert.ok(loader.cache.has(modulePath));
const isServerPath = path.resolve(
path.dirname(testIndex),
'../../../../../lit-html/node/is-server.js'
);
assert.ok(loader.cache.has(isServerPath));
});

test('resolves a root exported path (.)', async () => {
const loader = new ModuleLoader({global: window});
const result = await loader.importModule(
'./lit-import-from-root.js',
testIndex
);
const {module, path: modulePath} = result;
assert.is(module.namespace.litIsServer, true);
assert.ok(loader.cache.has(modulePath));
const litPath = path.resolve(
path.dirname(testIndex),
'../../../../../lit/index.js'
);
const isServerPath = path.resolve(
path.dirname(testIndex),
'../../../../../lit-html/node/is-server.js'
);
assert.ok(loader.cache.has(litPath));
assert.ok(loader.cache.has(isServerPath));
});

test.run();
@@ -0,0 +1,2 @@
import {isServer} from 'lit';
export const litIsServer = isServer;
@@ -0,0 +1,2 @@
import {isServer} from 'lit-html/is-server.js';
export const litIsServer = isServer;

0 comments on commit 2e13a38

Please sign in to comment.