Not working on windows
Tried to use this on a windows 10 machine but couldn't make it work, got different errors, like tests doesn't work, if I run the test script I get the following error:
"C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" test --scripts-prepend-node-path=auto
> [email protected] test
> mocha
Error: No test files found
Process finished with exit code 1
If I try to run tests via WebStorm
C:\Users\Kennedy\WebstormProjects\xiv-chat-client\test\index.ts:3
import { expect } from 'chai';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)
at Object.exports.requireOrImport (C:\Users\Kennedy\WebstormProjects\xiv-chat-client\node_modules\mocha\lib\esm-utils.js:56:20)
at async Object.exports.loadFilesAsync (C:\Users\Kennedy\WebstormProjects\xiv-chat-client\node_modules\mocha\lib\esm-utils.js:88:20)
at async singleRun (C:\Users\Kennedy\WebstormProjects\xiv-chat-client\node_modules\mocha\lib\cli\run-helpers.js:125:3)
at async Object.exports.handler (C:\Users\Kennedy\WebstormProjects\xiv-chat-client\node_modules\mocha\lib\cli\run.js:374:5)
Process finished with exit code 1
If I try to build it:
> [email protected] build
> npm run clean && npm run lint && tsc
> [email protected] clean
> (rm -r ./.nyc_output || true) && (rm -r ./coverage || true) && (rm -r ./dist || true)
'rm' is not recognized as an internal or external command,
operable program or batch file.
'true' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code 1
npm ERR! path C:\Users\Kennedy\WebstormProjects\xiv-chat-client
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c (rm -r ./.nyc_output || true) && (rm -r ./coverage || true) && (rm -r ./dist || true)
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Kennedy\AppData\Local\npm-cache\_logs\2021-09-04T20_49_56_774Z-debug.log
Honestly, I haven't used this project in quite some time. I'll try to take a look soon to see what's wrong.
You can replace the clean script in package.json with rd /s /q "./dist" | rd /s /q "./nyc_output" | rd /s /q "./coverage" @kennedyoliveira
Thanks for that, @Yochyo. Does it work for you, @kennedyoliveira?
I haven't really used Windows in more than a decade (since XP), so I'm admittedly a little out of touch and rarely take it into consideration. It would be nice to make these commands work cross-platform.
I just did a quick search and found this, but I'd hate to add a bunch of dependencies just to delete generated files:
https://docgov.dev/posts/npm-scripts/#delete-files--folder
I kind of like the last answer on SO, which is to use rm *.js || del *.js as a cross-platform delete:
https://stackoverflow.com/questions/48120889/cross-platform-rm-command#67216575
Does this line work for you?
"clean": "(rm -r ./.nyc_output || del ./.nyc_output || true) && (rm -r ./coverage || del ./coverage || true) && (rm -r ./dist || del ./dist || true)",
or this one?
"clean": "(rm -r ./.nyc_output || rd /s /q ./.nyc_output || true) && (rm -r ./coverage || rd /s /q ./coverage || true) && (rm -r ./dist || rd /s /q ./dist || true)",
I found a solution for "Error: No test files found" (running Git Bash on Windows 10):
- Delete file
test/mocha.opts - Add file
.mocharc.jsto the root of the project with the following contents:
"use strict"
module.exports = {
exit: true,
bail: true,
slow: 1000,
recursive: true,
extension: ['ts'],
require: ["ts-node/register", "source-map-support/register"]
}
- Rerun
npm run cover:check
Also, @chriswells0, none of the lines worked, but this one works both on linux and on windows:
"clean": "node -e \"var { rmdirSync, existsSync } = require('fs'), path = require('path'); ['./.nyc_output', './coverage', './dist'].forEach(fPath => {if (existsSync(path.join(__dirname, fPath))) rmdirSync(path.join(__dirname, fPath), { recursive: true })}); process.exit(0);\""
The mocha config was migrated at the end of last year. I've added the clean command as provided. Please let me know if anyone still has a problem on Windows and we'll reopen the issue.