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

Cannot run tests on Windows (PowerShell) #17

Open
Download opened this issue Jul 24, 2021 · 2 comments
Open

Cannot run tests on Windows (PowerShell) #17

Download opened this issue Jul 24, 2021 · 2 comments

Comments

@Download
Copy link

PS C:\ws\versioned-api> npm test

> versioned2@0.0.1 test C:\ws\versioned-api
> npm run lint && npm run unit-test && bin/check-deps && npm run api-test


> versioned2@0.0.1 lint C:\ws\versioned-api
> $(npm bin)/eslint {test/api,app,lib}

'$' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! versioned2@0.0.1 lint: `$(npm bin)/eslint {test/api,app,lib}`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the versioned2@0.0.1 lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\stijn\AppData\Roaming\npm-cache\_logs\2021-07-24T16_23_44_100Z-debug.log
npm ERR! Test failed.  See above for more details.

I need to be able to run tests so I can make PRs for this project.
So this will be my first PR I think.

@Download
Copy link
Author

Got a bit further:

PS C:\ws\versioned-api> npm test

> versioned2@0.0.1 test C:\ws\versioned-api
> npm run lint && npm run unit-test && bash bin/check-deps && npm run api-test


> versioned2@0.0.1 lint C:\ws\versioned-api
> eslint {test/api,app,lib}


> versioned2@0.0.1 unit-test C:\ws\versioned-api
> cross-env NODE_PATH=. jest

 PASS  lib/assert_types.test.js        
 PASS  app/relationships_helper.test.js
 PASS  lib/util.test.js
 PASS  lib/model_spec_schema.test.js
  ● Console

    console.info lib/json_schema.js:68
      jsonSchema.formatErrors - could not parse error={
          "keyword": "enum",
          "dataPath": ".properties['title'].type",
          "schemaPath": "#/definitions/simpleTypes/enum",
          "params": {
              "allowedValues": [
                  "array",
                  "boolean",
                  "integer",
                  "null",
                  "number",
                  "object",
                  "string"
              ]
          },
          "message": "should be equal to one of the allowed values"
      } for doc={
          "type": "object",
          "properties": {
              "title": {
                  "type": "foobar"
              }
          }
      }
    console.info lib/json_schema.js:68
      jsonSchema.formatErrors - could not parse error={
          "keyword": "type",
          "dataPath": ".properties['title'].type",
          "schemaPath": "#/properties/type/anyOf/1/type",
          "params": {
              "type": "array"
          },
          "message": "should be array"
      } for doc={
          "type": "object",
          "properties": {
              "title": {
                  "type": "foobar"
              }
          }
      }
    console.info lib/json_schema.js:68
      jsonSchema.formatErrors - could not parse error={
          "keyword": "anyOf",
          "dataPath": ".properties['title'].type",
          "schemaPath": "#/properties/type/anyOf",
          "params": {},
          "message": "should match some schema in anyOf"
      } for doc={
          "type": "object",
          "properties": {
              "title": {
                  "type": "foobar"
              }
          }
      }

 PASS  lib/json_schema.test.js      
 PASS  lib/model_access.test.js     
 PASS  lib/diff.test.js
 PASS  lib/coerce.test.js
 PASS  lib/password_hash.test.js    
 PASS  lib/mongo.test.js
(node:540) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
 PASS  lib/jwt.test.js
 PASS  lib/model_callbacks_helper.test.js
 PASS  lib/model_meta.test.js
 PASS  app/publish_helper.test.js     

Test Suites: 14 passed, 14 total
Tests:       68 passed, 68 total
Snapshots:   0 total
Time:        3.321s, estimated 4s
Ran all test suites.

> versioned2@0.0.1 api-test C:\ws\versioned-api
> cross-env NODE_PATH=. ./test/api/js/run      

info: Starting server with config={
    "TITLE": "Versioned API",
    "DESCRIPTION": "Supports custom content types and versioning",
    "NODE_ENV": "test",
    "PORT": "3006",
    "LOG_LEVEL": "debug",
    "CACHE_EXPIRY": "10",
    "MONGODB_URL": "mongodb://localhost:27017/versioned2_test",
    "JWT_SECRET": "393dabff04884cf89ce918f53924d63e",
    "JWT_EXPIRY": 2592000,
    "MODELS_LIMIT": 30,
    "PROPERTY_LIMIT": 20,
    "RATE_LIMIT": null,
    "ALGOLIASEARCH_APPLICATION_ID": null,
    "ALGOLIASEARCH_API_KEY": null,
    "ALGOLIASEARCH_API_KEY_SEARCH": null,
    "SENDGRID_API_KEY": null,
    "API_BASE_URL": "https://api.versioned.io/v1",
    "UI_BASE_URL": "https://app.versioned.io",
    "EMAIL_PREFIX": "Versioned",
    "EMAIL_ENABLED": false,
    "FROM_EMAIL": "noreply@versioned.io",
    "CONTACT_EMAIL": "info@versioned.io",
    "SYS_ROUTE_KEY": "22b46b0da4",
    "modules": {
        "logger": {},
        "response": {},
        "mongo": {}
    }
}
Could not connect to mongodb url=mongodb://localhost:27017/versioned2_test err=MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
error: Error thrown when starting server: MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 { MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at Timeout.waitQueueMember.timer.setTimeout [as _onTimeout] (C:\ws\versioned-api\node_modules\mongodb\lib\core\sdam\topology.js:430:30)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)
  name: 'MongoServerSelectionError',
  reason:
   TopologyDescription {
     type: 'Single',
     setName: null,
     maxSetVersion: null,
     maxElectionId: null,
     servers: Map { 'localhost:27017' => [ServerDescription] },
     stale: false,
     compatible: true,
     compatibilityError: null,
     logicalSessionTimeoutMinutes: null,
     heartbeatFrequencyMS: 10000,
     localThresholdMS: 15,
     commonWireVersion: null },
  [Symbol(mongoErrorContextSymbol)]: {} }
(node:14640) UnhandledPromiseRejectionWarning: MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at Timeout.waitQueueMember.timer.setTimeout [as _onTimeout] (C:\ws\versioned-api\node_modules\mongodb\lib\core\sda

As you can see, basic stuff is running now on PowerShell but I don't have MongoDB installed.
Also, I am not sure whether my changes aren't breaking stuff on Unix/Mac.
So I think I will need some help from you to complete this.

For Mongo, we might consider starting a Mongo server with Docker? At my work we are doing this and the nice thing about it is that you can just check out a project and it has a docker-compose.yml file that pulls, installs and starts a Docker image with the database in it and you are all set up.

I'd be willing to try that here but have to know what you think about all this first.
Let me make a PR so you can have a look at what I'm doing and see if you agree.

@Download
Copy link
Author

Notice that I'm executing Bash scripts like bin/check-deps by prepending bash to the command:

bash bin/check-deps

The 'shebang' in the first line of the file has no effect on Windows.... But bash works as long as you either have Git for Windows or Windows Subsystem for Linux (WSL) installed. Not sure which because I have both... But I wonder whether this breaks on Unix/Mac? If not it's a good solution I think. Let me know your thoughts.

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

No branches or pull requests

1 participant