wallabyjs / quokka

Repository for Quokka.js questions and issues
https://quokkajs.com
1.17k stars 31 forks source link

Getting error: Not implemented: window.prompt #933

Closed Zaindotea closed 7 months ago

Zaindotea commented 7 months ago

Issue description or question

I'm using the "jsdom-quokka-plugin", I installed it, it works great, but everytime I type "prompt("")" I get an error in the Quokka console, the index.html does works as expected and so does the Javascript file, but I'm afraid it might cause trouble in the future, and also, it's annoying to have a red wall in the console I've attempted to solve this on my own with no success

Is this issue related to Quokka not outputting the expected results of your code?: Yes/No

Yes

It does not run using node.js in cmd, since i'm using the jsdom plugin

Sample code

prompt("test")

Quokka.js Console Output

'Error: Not implemented: window.prompt 
    at module.exports (C:\Users\Zaindotea\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17) 
    at C:\Users\Zaindotea\node_modules\jsdom\lib\jsdom\browser\Window.js:898:7 
    at C:\Users\Zaindotea\Desktop\CSSDesde0\my50projects\holamundo\script.js:3:19 
    at Object.<anonymous> (C:\Users\Zaindotea\Desktop\CSSDesde0\my50projects\holamundo\script.js:5:3) 
    at Object.<anonymous> (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\esm-wallaby\esm.js:1:277482) 
    at _0x3ef0d2.<computed> (eval at <anonymous> (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\q\q.js:2075:6), <anonymous>:1:166328) 
    at c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\esm-wallaby\esm.js:1:271307 
    at Generator.next (<anonymous>) 
    at Zu (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\esm-wallaby\esm.js:1:271701) 
    at al (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\esm-wallaby\esm.js:1:273936) 
    at Object.<anonymous> (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\esm-wallaby\esm.js:1:275855) 
    at _0x3ef0d2.<computed> (eval at <anonymous> (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\q\q.js:2075:6), <anonymous>:1:166328) 
    at Object.quokkaStackTraceMarker (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\runners\node\quokka@1.0.0\initializer.js:15:15805) 
    at v.quokkaStackTraceMarker [as _onStart] (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\runners\node\quokka@1.0.0\initializer.js:15:15858) 
    at t (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\server.js:507:33284) 
    at v.start (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\server.js:507:33639) 
    at in:run (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\server.js:197:101621) 
    at WebSocket.<anonymous> (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\server.js:197:98509) 
    at WebSocket.emit (node:events:519:28) 
    at WebSocket.emit (node:domain:488:12) 
    at Receiver.ontext (c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\ws\lib\WebSocket.js:841:10) 
    at c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\ws\lib\Receiver.js:536:18 
    at c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\ws\lib\Receiver.js:368:7 
    at c:\Users\Zaindotea\.vscode\extensions\wallabyjs.quokka-vscode-1.0.627\dist\wallaby\node_modules\ws\lib\PerMessageDeflate.js:249:5 
    at afterWrite (node:internal/streams/writable:701:5) 
    at onwrite (node:internal/streams/writable:679:7) 
    at Zlib.cb (node:internal/streams/transform:191:7) 
    at Zlib.processCallback (node:zlib:613:8) undefined' 

Code editor version

Visual Studio Code v1.81.1

OS name and version

Windows 11

smcenlly commented 7 months ago

Quokka runs in node, and prompt (window.prompt to be more precise) is a browser specific thing.

With the interactive nature of Quokka scratch pads, you are better off writing the answer to your prompt directly in your code file (e.g. assign it to a variable and use that variable).

While jsdom emulates the browser behavior, it does not provide prompt as a feature. This means it won't work for Quokka either.

You can emulate the behavior yourself (in your code) by replacing the prompt function on window. For example:

console.log('foo');

window.prompt = () => {
  return 'myVariable';
};

console.log(window.prompt('Enter your name')) // Will return 'myVariable'

In the example above, you won't see a prompt. Quokka does not allow for values to be interactively captured from you when you run your file. Instead, we expect you will edit your code to set/update the value.