How to run mocha and mocha-phantomjs tests from one “npm test” command in node.js?

I like the following: “scripts”: { “test”: “npm run test-node && npm run test-browser”, “test-node”: “mocha -R spec ./test/node/index.js”, “test-browser”: “mocha-phantomjs ./test/browser/index.html”} The && only runs the second if the first passes, and you can run either separately if you want. Note that npm always uses the relative mocha (inside node_modules), not the global one, … Read more

How can I execute async Mocha tests (NodeJS) in order?

The point is not so much that “structured code runs in the order you’ve structured it” (amaze!) – but rather as @chrisdew suggests, the return orders for async tests cannot be guaranteed. To restate the problem – tests that are further down the (synchronous execution) chain cannot guarantee that required conditions, set by async tests, … Read more

Using webpack aliases in mocha tests

Okay so I realized that everything I was aliasing was in the src/ directory, so I simply needed to modify my npm run test script. { “scripts”: { “test”: “NODE_PATH=./src mocha ./src/**/test/spec.js –compilers js:babel-core/register –recursive” } } Probably won’t work for everyone, but that solved my issue.

Testing a redirect to a new route with Cypress

What you need to do is assert that the url is in the expected state. There are many commands in Cypress that can be used to make assertions about the url. Specifically, cy.url(), cy.location() or cy.hash() may meet your requirements. Probably the best example for your use case would be this: cy.location(‘pathname’).should(‘eq’, ‘/newthing/:id’)

How to suppress application logging messages from a node.js application when running unit tests?

In your app.js: if (process.env.NODE_ENV !== ‘test’) { app.use(express.logger()); } At the top of each of your mocha files: process.env.NODE_ENV = ‘test’; Update: We use this function in our import code: function logExceptOnTest(string) { if (process.env.NODE_ENV !== ‘test’) { console.log(string); } } Then, replace all your console.log(‘it worked’) with logExceptOnTest(‘it worked’). The basic trick is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)