-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bare import not working #3018
Comments
Thanks for the sample repo. It looks like it's missing your
|
@smcenlly quick response time, much appreciated! My communication can improve. Let me provide a bit more clarification: Building and Testing the module are done with two different typescript compiler configurations.
To execute a Build or Test use:
What works? Publishing or using the module.The module and its dependencies are resolved in es6 compatible browsers. import { Dictionary } from "dictionary" This works because the <script type="importmap">
{
"imports": {
"dictionary": "../node_modules/@browser-modules/typescript.dictionary/lib/dictionary.js",
"events": "../lib/events.js"
}
}
</script> The During development, adding and/or updating the source code: import { Dictionary } from "dictionary" Because of the compiler configuration: {
"paths": {
"dictionary": ["../node_modules/@browser-modules/typescript.dictionary/lib/dictionary.js"]
}
} What does not work? TestingBoth automated wallaby and manual karma: executed by npm script: Current way of testingImport dependency modules via a complete path import { Dictionary } from "../node_modules/@browser-modules/typescript.dictionary/lib/dictionary.js" This makes both automated wallaby and manual karma happy. Potential SolutionFor karma runner, it is possible to use a custom context.html file. I was thinking of using a custom html file that includes the same importmap used in |
I think ideally your Wallaby and Karma solution should be the same. You need something to process the module imports and re-write your aliases for you so they can resolved by the browser. For what you're looking to do, I myself would be setting up webpack for Karma with resolve aliases. Wallaby also supports webpack and the same webpack configuration that works with Karma should work with webpack. |
@smcenlly, I got my unit tests working via Karma without rewriting any alias. But not yet Wallaby. What I did was configure Karma to use a custom HTML context. customContextFile: "custom.context.html" my custom HTML file is a copy of what Karma uses by default. <script type="importmap">
{
"imports": {
"dictionary": "/base/node_modules/@browser-modules/typescript.dictionary/lib/dictionary.js"
}
}
</script> Help me out with Wallaby, please! I would really like to avoid implementing any bundler. Question:
|
@FlippieCoetser, To make Wallaby working in your repo you need to create the following file const importMap = {
imports: {
"@browser-modules/dictionary":
"/node_modules/@browser-modules/dictionary/lib/dictionary.js",
},
};
const element = document.createElement("script");
element.type = "importmap";
element.textContent = JSON.stringify(importMap);
document.currentScript.after(element); https://github.com/WICG/import-maps#dynamic-import-map-example and add the file path as the first entry to // typescript paths is an example of how to map an npm module name directly to a file path.
module.exports = function (wallaby) {
return {
files: [
+++ "aliases.js",
"src/**/*.ts",
"node_modules/@browser-modules/dictionary/lib/dictionary.js",
],
tests: ["test/*.ts"],
trace: true,
compilers: {
"**/*.ts": wallaby.compilers.typeScript({
module: "es2020",
target: "es2020",
sourceMap: true,
inlineSources: true,
}),
}
};
};
You may consider using the same file for Karma to have only one source of truth for path aliases in your project. |
@NikGovorov works like a charm! as per your suggestion I also simplified Karma using |
Issue description or question
Typescript path mapping workaround as described here, does not work.
Use-case seems to be different:
Rather than
import { Dictionary } from '/dictionary.js'
I would like to doimport { Dictionary } from 'dictionary'
: a bare importAlthough the testing does not work,
I am able to build the module and use it chrome browser.
To build the module with bare imports requires two pieces:
index.html
To make the testing work I have to provide a relative path:
import { Dictionary } from "../node_modules/@browser-modules/typescript.dictionary/lib/dictionary.js"
in events.ts file.A small demonstratable project can be downloaded from GitHub here
The HTML script type importmap works great with the chrome browser, is there a way to insert the importmap into the HTML file used by wallaby? or is there a different approach?
The text was updated successfully, but these errors were encountered: