Skip to content

Commit

Permalink
Prepare using setup.js as the main entrypoint for tests (#426)
Browse files Browse the repository at this point in the history
* Prepare using setup.js as the main entrypoint for tests
  • Loading branch information
patrick-tolosa authored Jul 20, 2020
1 parent 0c64356 commit 3b9b997
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recursive": true,
"retries": 3
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"types": "types",
"scripts": {
"test": "tools/scripts/test.sh",
"test:unit": "mocha --recursive test/unit",
"test:unit": "tools/scripts/test.es6.unit.sh",
"test-with-temp-cloud": "tools/scripts/tests-with-temp-cloud.sh",
"dtslint": "tools/scripts/ditslint.sh",
"lint": "tools/scripts/lint.sh",
Expand Down
1 change: 0 additions & 1 deletion test/integration/api/admin/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ function findByAttr(elements, attr, value) {


describe("api", function () {
this.retries(3);
var contextKey = `test-key${UNIQUE_JOB_SUFFIX_ID}`;
before("Verify Configuration", function () {
let config = cloudinary.config(true);
Expand Down
1 change: 0 additions & 1 deletion test/integration/api/search/search_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const SEARCH_TAG = 'npm_advanced_search_' + UNIQUE_JOB_SUFFIX_ID;


describe("search_api", function () {
this.retries(3);
describe("unit", function () {
it('should create empty json', function () {
var query_hash = cloudinary.v2.search.instance().to_query();
Expand Down
1 change: 0 additions & 1 deletion test/integration/api/uploader/archivespec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ sharedExamples('archive', function () {
});

describe("archive", function () {
this.retries(3);
includeContext('archive');
describe("utils", function () {
describe('.generate_zip_download_url', function () {
Expand Down
1 change: 0 additions & 1 deletion test/integration/api/uploader/uploader_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const {
require('jsdom-global')();

describe("uploader", function () {
this.retries(3);
before("Verify Configuration", function () {
var config = cloudinary.config(true);
if (!(config.api_key && config.api_secret)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const keys = require('lodash/keys');
const Q = require('q');
const cloudinary = require("../cloudinary");
const helper = require("./spechelper");
const TIMEOUT = require('./testUtils/testConstants').TIMEOUT;
const cloudinary = require("../../cloudinary");
const helper = require("../spechelper");
const TIMEOUT = require('../testUtils/testConstants').TIMEOUT;
const api = cloudinary.v2.api;

describe('Cloudinary::Api', function () {
Expand Down
3 changes: 0 additions & 3 deletions test/mocha.opts

This file was deleted.

9 changes: 5 additions & 4 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
global.expect = require('expect.js');
require('./testUtils/testBootstrap');


require('dotenv').load({
silent: true
});

if (!process.env.CLOUDINARY_URL) {
throw 'Could not start tests - Cloudianry URL is undefined'
}

global.expect = require('expect.js');
require('./testUtils/testBootstrap');
3 changes: 3 additions & 0 deletions test/testUtils/testConstants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require('dotenv').load({
silent: true
});
const UNIQUE_JOB_SUFFIX_ID = process.env.TRAVIS_JOB_ID || Math.floor(Math.random() * 999999);

// create public ID string for tests
Expand Down
7 changes: 6 additions & 1 deletion tools/scripts/test.es5.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#!/bin/bash
mocha --recursive --require 'babel-register' --require 'babel-polyfill' test/

# --File ensures that setup.js runs first
# This file should be in the config under a 'require' key
# However Mocha 6 does not expose before, beforeEach after etc. at that time
# When Removing support of Node 6 and 8 and using Mocha 8, we should move this to the mocharc.json file
mocha --require './test/setup.js' --require 'babel-register' --require 'babel-polyfill' "./test/**/*spec.js"
14 changes: 12 additions & 2 deletions tools/scripts/test.es6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ done

if [ "$COLLECT_COVERAGE" -eq "1" ]; then
echo 'Running code coverage test on ES6 code'
nyc --reporter=html mocha --recursive test/

# --File ensures that setup.js runs first
# This file should be in the config under a 'require' key
# However Mocha 6 does not expose before, beforeEach after etc. at that time
# When Removing support of Node 6 and 8 and using Mocha 8, we should move this to the mocharc.json file
nyc --reporter=html mocha --file "./test/setup.js" "./test/**/*spec.js"
exit;
else
echo 'Running tests on ES6 Code'
mocha --recursive test/

# --File ensures that setup.js runs first
# This file should be in the config under a 'require' key
# However Mocha 6 does not expose before, beforeEach after etc. at that time
# When Removing support of Node 6 and 8 and using Mocha 8, we should move this to the mocharc.json file
mocha --file "./test/setup.js" "./test/**/*spec.js"
fi
5 changes: 5 additions & 0 deletions tools/scripts/test.es6.unit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# --File ensures that setup.js runs first
# This file should be in the config under a 'require' key
# However Mocha 6 does not expose before, beforeEach after etc. at that time
# When Removing support of Node 6 and 8 and using Mocha 8, we should move this to the mocharc.json file
mocha --file "./test/setup.js" "./test/unit/**/*spec.js"

0 comments on commit 3b9b997

Please sign in to comment.