Open pmosconi opened 5 years ago
Thanks for reporting this @pmosconi Need to check how to fix this! Any help on it is very much appreciated if anyone else runs into this 👍
For simple scripts the best solution is using cross-env:
"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"
I'm not sure about quote expansion though.
Pmosconi's solution worked for me on Windows. I think the book should be updated to note this for Windows users as I spent about 2 hours trying to figure out what was going on before coming here. I am guessing there are many readers who have been stuck at this part of the book.
Thank you for confirming @tmstani23 Sorry that you had to go through this trouble ... It's always difficult for me to align all operating systems on a topic. I will fix it!
In the end, did you use
"test-server": "set TEST_DATABASE=mytestdatabase&& npm start",
"test": "mocha --require @babel/register src/**/*.spec.js"
or
"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"
or both and both worked for you?
Thank you again!
I used:
"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/*/.spec.js"
I haven't tried cross-env. I'm wondering if that's a library or a part of node? Thanks for the response. I've really been enjoying the book so far and learning so much!
Regards, Timothy Stanislav
On Tue, Jan 15, 2019 at 7:02 PM Robin Wieruch notifications@github.com wrote:
Thank you for confirming @tmstani23 https://github.com/tmstani23 Sorry that you had to go through this trouble ... It's always difficult for me to align all operating systems on a topic. I will fix it!
In the end, did you use
"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/*/.spec.js"
or
"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"
or both and both worked for you?
Thank you again!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate/issues/44#issuecomment-454611212, or mute the thread https://github.com/notifications/unsubscribe-auth/AG3iALTdqL_Lr8PKfmIcucOP4zTRF1HXks5vDno_gaJpZM4Zl2ph .
-- Timothy Stanislav Cell:507-261-9867 Email:tmstani23@gmail.com
cross-env is an npm module you have to add to your dev dependencies.
paolo
Da: Tim Stanislav notifications@github.com Inviato: mercoledì 16 gennaio 2019 14:38 A: the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate fullstack-apollo-express-postgresql-boilerplate@noreply.github.com Cc: Paolo Mosconi pmosconi@gmail.com; Mention mention@noreply.github.com Oggetto: Re: [the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate] npm run scripts on Windows (#44)
I used:
"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/*/.spec.js"
I haven't tried cross-env. I'm wondering if that's a library or a part of node? Thanks for the response. I've really been enjoying the book so far and learning so much!
Regards, Timothy Stanislav
On Tue, Jan 15, 2019 at 7:02 PM Robin Wieruch <notifications@github.com mailto:notifications@github.com > wrote:
Thank you for confirming @tmstani23 https://github.com/tmstani23 Sorry that you had to go through this trouble ... It's always difficult for me to align all operating systems on a topic. I will fix it!
In the end, did you use
"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/*/.spec.js"
or
"test-server": "cross-env TEST_DATABASE=mytestdatabase npm start"
or both and both worked for you?
Thank you again!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate/issues/44#issuecomment-454611212, or mute the thread https://github.com/notifications/unsubscribe-auth/AG3iALTdqL_Lr8PKfmIcucOP4zTRF1HXks5vDno_gaJpZM4Zl2ph .
-- Timothy Stanislav Cell:507-261-9867 Email:tmstani23@gmail.com
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate/issues/44#issuecomment-454781360 , or mute the thread https://github.com/notifications/unsubscribe-auth/AG8cIoaSYry6QtcdpVJDRcsfgEqCVkc9ks5vDysbgaJpZM4Zl2ph . https://github.com/notifications/beacon/AG8cIqB2CMV89-G98ZA-VSgWCN4hfqnTks5vDysbgaJpZM4Zl2ph.gif
npm run scripting syntax is slightly different on Windows due to the underlying shell being used. Usually the default is cmd.exe (the old DOS), even though it is possible to override the default.
The key changes required for the testing scripts (p. 315 of the book) are:
"test-server": "set TEST_DATABASE=mytestdatabase&& npm start", "test": "mocha --require @babel/register src/**/*.spec.js"
In test-server, there is no space between the variable's value and && on purpose otherwise trailing spaces would be added to the value (https://stackoverflow.com/questions/25112510/how-to-set-environment-variables-from-within-package-json-node-js#comment58812038_27090755). Note thatTEST_DATABASE=mytestdatabase && npm start
will not work in Linux because && starts another shell where the variable is not defined.In test, single quote are omitted otherwise * are not expanded, or at leasr I think.
Unfortunately there is no way to define cross environment scripts without using external packages.