Skip to content
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

Running tests on Windows #323

Closed
steven-supersolid opened this issue Feb 9, 2016 · 19 comments · Fixed by #831
Closed

Running tests on Windows #323

steven-supersolid opened this issue Feb 9, 2016 · 19 comments · Fixed by #831

Comments

@steven-supersolid
Copy link
Contributor

Running npm test gives an error with babel-node / babel-instanbul

I added cross-env to enable setting environment variables in npm script. I want to submit a PR with this change and a fix to get babel working if possible.

C:\development\parse-server-fork>npm test

[email protected] pretest C:\development\parse-server-fork
cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.0.8} ./node_modules/.bin/mongodb-runner start

  • Starting a MongoDB deployment to test against...
    [email protected] test C:\development\parse-server-fork
    cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node ./node_modules/.bin/babel-istanbul cover -x /spec/ ./node_modules/.bin/jasmine

C:\development\parse-server-fork\node_modules.bin\babel-istanbul:4
case uname in
^^^^

SyntaxError: Unexpected token case
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at C:\development\parse-server-fork\node_modules\babel-cli\lib_babel-node.js:161:27
at Object. (C:\development\parse-server-fork\node_modules\babel-cli\lib_babel-node.js:162:7)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
npm ERR! Test failed. See above for more details.

@steven-supersolid
Copy link
Contributor Author

#335

@nlutsenko
Copy link
Contributor

Looks like this is done now.

@aneeshd16
Copy link
Contributor

With new changes, this fails again on Windows
https://github.com/ParsePlatform/parse-server/blob/master/package.json#L59
probably because of the if condition

@flovilmart
Copy link
Contributor

What version of Windows do you use? What command interpreter?

@aneeshd16
Copy link
Contributor

Windows 10 64 bit
PowerShell:


> [email protected] pretest B:\Projects\Parse Server\parse-server
> cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.0.8} ./node_modules/.bin/mongodb-runner start


> [email protected] test B:\Projects\Parse Server\parse-server
> cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node $(if [ "$CODE_COVERAGE" = "1" ]; then echo './node_modules/babel-istanbul/lib/cli.js cover -x **/spec/**'; fi;) ./node_modules/jasmine/bin/jasmine.js

./node_modules/jasmine/bin/jasmine.js was unexpected at this time.

B:\Projects\Parse Server\parse-server>  "B:\Projects\Parse Server\parse-server\node_modules\.bin\\node.exe"  "B:\Projects\Parse Server\parse-server\node_modules\.bin\\..\cross-env\bin\cross-env.js" NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node $(if [ "$CODE_COVERAGE" = "1" ]; then echo './node_modules/babel-istanbul/lib/cli.js cover -x **/spec/**'; fi;) ./node_modules/jasmine/bin/jasmine.js
npm ERR! Test failed.  See above for more details.

Same output with cmd.

@aneeshd16
Copy link
Contributor

Also, since shebangs are not supported on Windows, npm start and npm run dev do not work either.
Why not set "start": "./bin/parse-server" to `"start": "node ./bin/parse-server"?

@steven-supersolid
Copy link
Contributor Author

I get the same issue. Suggest removing the if and having a separate npm script for coverage as a quick fix, plus the other changes would be nice too.

I can make a PR next week unless @aneeshd16 wants to take it before then?

@flovilmart
Copy link
Contributor

let me think about something

@flovilmart
Copy link
Contributor

See #831

@steven-supersolid
Copy link
Contributor Author

Nice 👍

@aneeshd16
Copy link
Contributor

@steven-supersolid Does this work for you? It still throws an error on my system:


> [email protected] pretest B:\Projects\Parse Server\parse-server
> cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.0.8} ./node_modules/.bin/mongodb-runner start


> [email protected] test B:\Projects\Parse Server\parse-server
> cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js

module.js:339
    throw err;
    ^

Error: Cannot find module 'B:\Projects\Parse Server\parse-server\$COVERAGE_OPTION'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Function.Module.runMain (module.js:467:10)
    at B:\Projects\Parse Server\parse-server\node_modules\babel-cli\lib\_babel-node.js:161:27
    at Object.<anonymous> (B:\Projects\Parse Server\parse-server\node_modules\babel-cli\lib\_babel-node.js:162:7)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
npm ERR! Test failed.  See above for more details.

aneeshd16 added a commit to aneeshd16/parse-server that referenced this issue Mar 7, 2016
Use `npm run test:win` to run tests on Windows. Fixes parse-community#323.
Variables like `$COVERAGE_OPTION` are not supported in Windows.
@steven-supersolid
Copy link
Contributor Author

Yes I got the same issue, also npm run coverage doesn't work either but #886 does allow the tests to be run (I get a TypeError on a test but not sure if that is a problem on my end)

@aneeshd16
Copy link
Contributor

Yes, I get the same error. I too thought it was only on my end

B:\Projects\Parse Server\parse-server\spec\FileLoggerAdapter.spec.js:38
        expect(results[0].message).toEqual('testing info logs');
                         ^

TypeError: Cannot read property 'message' of undefined
    at B:\Projects\Parse Server\parse-server\spec\FileLoggerAdapter.spec.js:38:26
    at ParsePromise.<anonymous> (B:\Projects\Parse Server\parse-server\src\Adapters\Logger\FileLoggerAdapter.js:9:17440)
    at ParsePromise.wrappedResolvedCallback (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:139:41)
    at ParsePromise.resolve (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:72:36)
    at resolveOne (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:471:29)
    at ParsePromise.object.then.errors.(anonymous function) (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:480:13)
    at ParsePromise.wrappedResolvedCallback (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:139:41)
    at ParsePromise.resolve (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:72:36)
    at ReadFileContext.callback (B:\Projects\Parse Server\parse-server\src\Adapters\Logger\FileLoggerAdapter.js:9:16189)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:303:13)

Seems like results is undefined. Interestingly, this error does not occur on my Ubuntu machine.

@flovilmart
Copy link
Contributor

there is a big change a path.resolve didn't use path.separator

@aneeshd16
Copy link
Contributor

Changing promise.resolve([]) to promise.reject([]) here https://github.com/ParsePlatform/parse-server/blob/master/src/Adapters/Logger/FileLoggerAdapter.js#L191 causes the test to rightfully fail and allows running of the rest of the tests. However, i do not know the impact of this change on other code. Logically, if there is an error, the promise should be rejected, right? @flovilmart

@flovilmart
Copy link
Contributor

It depends if you want to propagate the error or just swallow it

@aneeshd16
Copy link
Contributor

Okay modified the test to fail if it gets an empty array: #946

@aneeshd16
Copy link
Contributor

I have been playing around with FileLoggerAdapter and there are multiple problems that need to be solved:

  1. Using path.resolve(<filename>) works for generating a valid Windows filename from the nix ones.
  2. But, the _getFileName() (Link to code) method outputs a filename that contains the : character which cannot be part of a filename on Windows.
    How do we solve this? If we replace all : with another character (like -) it will be able to write the file on disk. But people who have already deployed on *nix systems won't be able to read old logs.
    Can we detect the OS and set the filename accordingly? What are the implications for having different filenames for logs across OSes?
  3. After I had implemented these fixes, the tests failed again because of this: https://github.com/ParsePlatform/parse-server/blob/master/spec/FileLoggerAdapter.spec.js#L8
    Stuff I tried to solve this:
  • Added path.resolve. Go the error:
Stack:
    Error: EPERM: operation not permitted, lstat 'B:\Projects\Parse Server\parse-server\test_logs\2016-03-10T18-30-00.000Z.info'
        at Error (native)
        at Object.fs.lstatSync (fs.js:839:18)
        at B:\Projects\Parse Server\parse-server\spec\FileLoggerAdapter.spec.js:12:13
        at Array.forEach (native)
        at deleteFolderRecursive (B:\Projects\Parse Server\parse-server\spec\FileLoggerAdapter.spec.js:10:26)
        at Object.<anonymous> (B:\Projects\Parse Server\parse-server\spec\FileLoggerAdapter.spec.js:53:5)
  • Used rimraf
    1. Tried rimraf async, passed the done() method as the callback to rimraf. got the error: Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
    2. Tried rimraf.sync() and hit this issue Windows support (ENOTEMPTY issues) isaacs/rimraf#72

I am starting to wonder if it is really worth the trouble to fix this.

@steven-supersolid
Copy link
Contributor Author

I didn't get anywhere with this either. It seems the logs are not even being written on Windows and for me I don't mind that parse-server will not run on Windows, but I do want the tests to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants