You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have tried to build the project for esnext but I have some problems into some dependencies. If you want I can provide a sample project to debug, logs or what you need :)
I will check in the meantime the solutions you provide, thanks for the quick response and the effort of this library! I think it's a awesome solution for having regression testing on accessibility, and it's something really needed in this times to aware about a11y ;)
I received the following error and it crashes, I am going to check that dependency to see if this can be fixed :)
Ah apologies, I should have tested more thoroughly 🤦
I’ll take a look as to whether there is anything I can do in this package to work around the issue, otherwise I guess we ask the question again on the aria-query thread!
I have been playing around with the dependencies, making overrides from aria-roles to aria-roles-esm, and it's not the only dependency that causes problems in a ESM build. I also hit the wall with lz-string, that doesn't like that is going to work, so looks like it would be more difficult than assumed.
The only solution that comes to my mind (and I don't like too much), is to create a webpack/rollup/whatever bundle with all the dependencies embeed, so they are also processed and converted to ESM code. WDYT?
See also testing-library/dom-testing-library#995 it looks like this has been raised before, but the issue was quite muddled and closed based on a change that doesn’t quite go the whole way.
Maybe worth raising an issue on Testing Library to see what appetite would be?
Alternatively there are some comments that suggest you can use a commonjs Rollup plugin within the web-test-runner config that might help compile for ESM?
Bare with, have reproduced and think making ground.
TIL a testEnvironment of jsdom will automatically assume a package export of browser which doesn't seem unreasonable... except ESM can be executed in a browser, but not handled at all well in a Jest context, hence the error r.e. export.
Question about the inclusion of the file. I’m trying to have 2 × describe blocks for each page: 1 × jest, 1 × virtual-screen-reader. Prior to the change you just made, what you see below was the only way I could get it working. Am I missing something completely obvious; is there an easier way to include this? I think I’m at that stage of the day where I’d fail spelling my own name correctly.
functionsetupA11yPage(){document.body.innerHTML=`<div> …</div>`;}describe('matchers',()=>{beforeEach(()=>{setupA11yPage();});afterEach(()=>{document.body.innerHTML=``;});// I’m writing `@guidepup/jest` tests here — see above, where errors are mentioned.describe('snapshot tests',()=>{test('…',async()=>{});});// I’m writing `@guidepup/virtual-screen-reader` tests here.describe('virtual screen reader tests',()=>{// navigate by headingstest('…',async()=>{// I can’t async the `describe` block, so I have to put this inside each// `test` block I write — which seems less than ideal, or wrong (to me).const{ virtual }=awaitimport('@guidepup/virtual-screen-reader');});});});
On the first point, let’s raise the issue on that repo and will take a look why the types aren’t propagating through.
On the latter, hopefully you should just be able use a single import statement at the top of the file:
import{virtual,Virtual}from"@guidepup/virtual-screen-reader";functionsetupA11yPage(){document.body.innerHTML=`<div> …</div>`;}describe('matchers',()=>{beforeEach(()=>{setupA11yPage();});afterEach(()=>{document.body.innerHTML=``;});describe('snapshot tests',()=>{test('…',async()=>{});});describe('virtual screen reader tests',()=>{// navigate by headingstest('…',async()=>{// Use the easy start exportawaitvirtual.start({ … });// … rest of test// Or use the class constructor if you need multiple instances - e.g. sharding in parallel.constvsr=newVirtual();awaitvsr.start({ … });// … rest of test});});});
Give package exports weren’t quite right before it may have prompted you async importing per test if was erroring?
Are you using "type": "module" in your package.json or .mjs/.mts and .cjs/.cts extensions?
What are the values you are using for these keys in your tsconfig.json?
target
module
moduleResolution
esModuleInterop
The first error indicates that your project is configured to consider the file a CommonJS module. The use of the import with VSR will target the ESM version of the library which can't be used in a CommonJS context except as a dynamic import.
The second screenshot is how you import the bundled, minified, browser compatible ESM version of the library. This isn't something that would expect folks to use outside of a browser context.
Pending further info, would suggest your paths forward are one of:
Use a dynamic import at the beginning of your test files in place of a static import, and continue to use the CJS module setup as-is:
Update your package.json (via "type": "module") and/or the file extension (i.e. .mts) to indicate that this file is in fact ESM.
Update your tsconfig.json to use a "moduleResolution": "bundler" to allow module resolution via VSR's exports instead of through your package module type / extension.
Failing that there is the option for the package to publish subpath exports to work around this, in your case something like @guidepup/virtual-screen-reader/cjs
Will have a play my end with an example matching that setup and see if any other options.
Yeah, I get shouted at for having that at the top.
The current file is a CommonJS module and cannot use 'await' at the top level.ts(1309)
We inherited the project, which was already forked off a previous project. It’s not a great situation for the developers but I’m trying to improve things for the users.
FAIL src/pages/__test__/AccessibilityPage.a11y.tsx
● Test suite failed to run
src/pages/__test__/AccessibilityPage.a11y.tsx:4:25 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@guidepup/virtual-screen-reader")' call instead.
To convert this file to an ECMAScript module, add the field `"type": "module"` to '…/package.json'.
import { virtual } from '@guidepup/virtual-screen-reader';
Alternatively if can share as much of your tsconfig and jest config/setup as is permittable then can have a better shot of recreating.
—-
Update: I’m now not optimistic, but introduced some new tests which found some type issues and are now resolved for node16 tsconfigs in the latest patch - given you’re on node (aka node10) not expecting to resolve, but it is a fix for a similar error.
Property 'toMatchScreenReaderSnapshot' does not exist on type'JestMatchers<null>'.
Property 'toMatchScreenReaderInlineSnapshot' does not exist on type'JestMatchers<null>'.
But all is well if I add it into each test file. Not sure if that will mean anything to you, but I'm still happy to be tagged into any Issues for that particular beast.
Activity
vlaraort commentedon Feb 14, 2024
I have tried to build the project for esnext but I have some problems into some dependencies. If you want I can provide a sample project to debug, logs or what you need :)
cmorten commentedon Feb 14, 2024
Hey @vlaraort 👋
The ask is straight-forward enough so should be reasonable to do.
Some thought needed as to the best approach as there are a few approaches, e.g. using .cjs and .mjs vs 2 package.json alternatives.
In the meantime you might be able to unblock yourself by using the likes of https://jspm.org/, https://esm.sh/, or https://jsr.io/
vlaraort commentedon Feb 14, 2024
I don't think you need two package.json, only ship two builds in the same package, and use this approach
https://antfu.me/posts/publish-esm-and-cjs
I will check in the meantime the solutions you provide, thanks for the quick response and the effort of this library! I think it's a awesome solution for having regression testing on accessibility, and it's something really needed in this times to aware about a11y ;)
cmorten commentedon Feb 14, 2024
Yep that’s the first (and newer) approach where you ship different extensions and utilise the newish exports field 😊
Prior that existing, the only option was to publish two packages, one with type:module.
Not sure what the tradeoffs are of the two approaches, but suspect the more modern approach is the way to go.
cmorten commentedon Feb 17, 2024
Hi @vlaraort 👋
I’ve hopefully now updated the package to dual support CJS and ESM. Please could you try with
0.18.0?vlaraort commentedon Feb 20, 2024
I tried, thanks!
I received the following error and it crashes, I am going to check that dependency to see if this can be fixed :)
vlaraort commentedon Feb 20, 2024
In fact, here are some information regarding the same dependency, in the same library
A11yance/aria-query#48
cmorten commentedon Feb 20, 2024
Ah apologies, I should have tested more thoroughly 🤦
I’ll take a look as to whether there is anything I can do in this package to work around the issue, otherwise I guess we ask the question again on the aria-query thread!
vlaraort commentedon Feb 20, 2024
Looks like they don't really want to provide a ESM export because reasons
A11yance/aria-query#485
But, there is a fork that makes the ESM build, maybe we can try with this fork of aria-roles instead?
https://github.com/KonnorRogers/aria-query/tree/konnorrogers/publish-modern-build
vlaraort commentedon Feb 21, 2024
I have been playing around with the dependencies, making overrides from aria-roles to aria-roles-esm, and it's not the only dependency that causes problems in a ESM build. I also hit the wall with lz-string, that doesn't like that is going to work, so looks like it would be more difficult than assumed.
The only solution that comes to my mind (and I don't like too much), is to create a webpack/rollup/whatever bundle with all the dependencies embeed, so they are also processed and converted to ESM code. WDYT?
cmorten commentedon Feb 21, 2024
See also testing-library/dom-testing-library#995 it looks like this has been raised before, but the issue was quite muddled and closed based on a change that doesn’t quite go the whole way.
Maybe worth raising an issue on Testing Library to see what appetite would be?
Alternatively there are some comments that suggest you can use a commonjs Rollup plugin within the web-test-runner config that might help compile for ESM?
In the meantime using the likes of https://esm.sh/@guidepup/virtual-screen-reader@0.19.0 as mentioned before might be the way to go for now.
cmorten commentedon Feb 21, 2024
See https://modern-web.dev/docs/dev-server/plugins/rollup/ for a guide on how to use the Rollup plugins within web test runner, specifically the commonjs one.
Away from desk so can’t test atm
12 remaining items
philsherry commentedon Jun 24, 2024
Yeah, it’s already in the right key:
setupFilesAfterEnv: ['<rootDir>/jest.setup.js']Jest’s docs have had that right for ages.
jlp-craigmorten commentedon Jun 24, 2024
Heya @philsherry
Bare with, have reproduced and think making ground.
TIL a
testEnvironmentofjsdomwill automatically assume a package export ofbrowserwhich doesn't seem unreasonable... except ESM can be executed in a browser, but not handled at all well in a Jest context, hence the error r.e.export.REF: https://jestjs.io/docs/configuration#testenvironmentoptions-object
Going to try releasing a new version with some exports tweaks to get this workable, hopefully without additional config.
jlp-craigmorten commentedon Jun 24, 2024
@philsherry can you try
@guidepup/virtual-screen-reader@^0.25.0and@guidepup/jest@^0.4.0and see if it gets us any closer?philsherry commentedon Jun 24, 2024
Mate, looking good.
@guidepup/jestis firing nicely from the setup file now.I’m seeing this, though, and feel free to take this up on the
@guidepup/jestrepo.Question about the inclusion of the file. I’m trying to have 2 ×
describeblocks for each page: 1 ×jest, 1 ×virtual-screen-reader. Prior to the change you just made, what you see below was the only way I could get it working. Am I missing something completely obvious; is there an easier way to include this? I think I’m at that stage of the day where I’d fail spelling my own name correctly.cmorten commentedon Jun 24, 2024
On the first point, let’s raise the issue on that repo and will take a look why the types aren’t propagating through.
On the latter, hopefully you should just be able use a single import statement at the top of the file:
Give package exports weren’t quite right before it may have prompted you async importing per test if was erroring?
philsherry commentedon Jun 25, 2024
Even after making those changes, it’s barking at me in one of two ways.
Happy for you to open new Issues and just tag me into them.
jlp-craigmorten commentedon Jun 26, 2024
@philsherry are you able to share the following?
"type": "module"in yourpackage.jsonor.mjs/.mtsand.cjs/.ctsextensions?tsconfig.json?targetmodulemoduleResolutionesModuleInteropThe first error indicates that your project is configured to consider the file a CommonJS module. The use of the import with VSR will target the ESM version of the library which can't be used in a CommonJS context except as a dynamic import.
The second screenshot is how you import the bundled, minified, browser compatible ESM version of the library. This isn't something that would expect folks to use outside of a browser context.
Pending further info, would suggest your paths forward are one of:
Use a dynamic import at the beginning of your test files in place of a static import, and continue to use the CJS module setup as-is:
Update your
package.json(via"type": "module") and/or the file extension (i.e..mts) to indicate that this file is in fact ESM.Update your
tsconfig.jsonto use a"moduleResolution": "bundler"to allow module resolution via VSR'sexportsinstead of through your package module type / extension.philsherry commentedon Jun 27, 2024
"type": "module"in ourpackage.jsonor.mjs/.mtsand.cjs/.ctsextensions.tsconfig.jsonvalues:{ "esModuleInterop": true, "module": "CommonJS", "moduleResolution": "node", "target": "es2020" }cmorten commentedon Jun 27, 2024
Let me know how goes!
Failing that there is the option for the package to publish subpath exports to work around this, in your case something like
@guidepup/virtual-screen-reader/cjsWill have a play my end with an example matching that setup and see if any other options.
philsherry commentedon Jun 27, 2024
Yeah, I get shouted at for having that at the top.
We inherited the project, which was already forked off a previous project. It’s not a great situation for the developers but I’m trying to improve things for the users.
cmorten commentedon Jun 27, 2024
I’ll look at providing an export for your setup.
TLA was only reasonably recent so perhaps overly hopeful with your tsconfig values 😂
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#top-level-await
jlp-craigmorten commentedon Jun 27, 2024
@philsherry had another go fiddling with the package exports, can you try again with:
@guidepup/virtual-screen-reader@^0.26.0@guidepup/jest@^0.5.0Where hopefully can just use static
importstatements for both libraries at the top of the appropriate files.E.g. see https://github.com/guidepup/jest/blob/main/examples/typescript-legacy as an example (though in your jest setup file will have the
import "@guidepup/jest";instead of a direct reference to the lib directory).philsherry commentedon Jun 27, 2024
Updated. Now I’m getting this.
FAIL src/pages/__test__/AccessibilityPage.a11y.tsx ● Test suite failed to run src/pages/__test__/AccessibilityPage.a11y.tsx:4:25 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@guidepup/virtual-screen-reader")' call instead. To convert this file to an ECMAScript module, add the field `"type": "module"` to '…/package.json'. import { virtual } from '@guidepup/virtual-screen-reader';FWIW, I’ve hated this project since I joined it.
cmorten commentedon Jun 27, 2024
Hmm, starting to get a bit stuck then… without being able to see more of your projects setup 😅
Perhaps worth comparing against the https://github.com/guidepup/jest/blob/main/examples/typescript-legacy example and seeing where things are differing and sharing?
Alternatively if can share as much of your tsconfig and jest config/setup as is permittable then can have a better shot of recreating.
—-
Update: I’m now not optimistic, but introduced some new tests which found some type issues and are now resolved for node16 tsconfigs in the latest patch - given you’re on node (aka node10) not expecting to resolve, but it is a fix for a similar error.
philsherry commentedon Jul 2, 2024
I ended up being off sick for a couple of days. Came back to find your update edited in, so I've just updated things and… my tests are… passing? 🫣
Note: Unless I add
@guidepup/jestinto the test file as well—despite it being referenced in the setup file—like so:…then I get those errors I mentioned:
But all is well if I add it into each test file. Not sure if that will mean anything to you, but I'm still happy to be tagged into any Issues for that particular beast.
Many thanks for sticking with me through this. 🙏