How to use the mocha.suite function in mocha

To help you get started, we’ve selected a few mocha examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bookercodes / communitycasts.co / tests / validateScreencastInput.js View on Github external
// @flow

import {expect} from 'chai'
import {suite, test} from 'mocha';
import validator from '../source/middleware/validateScreencastInput.js'
import sinon from 'sinon'
import httpMocks from "node-mocks-http";
import mockery from 'mockery'

suite('validateScreencastInput', () => {

  test('should export a function', () => {
    expect(validator).to.be.a('function')
  })

  test('should call next middleware function when input is valid', () => {
    const req = httpMocks.createRequest({
      body: {
        url: 'https://www.youtube.com/watch?v=qsDvJrGMSUY',
        tags: 'tag1, tags2'
      }
    })
    const res = httpMocks.createResponse()
    const next = sinon.spy()

    validator(req, res, next)
github pkgjs / statusboard / test / index.js View on Github external
const pkg = require('../package.json')
const statusboard = require('../')
const { Config } = statusboard

// These tests require a github token
assert(process.env.GITHUB_TOKEN, `
Tests require GITHUB_TOKEN to be a valid GitHub personal token.
See: https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line

Then run:

  $ echo "GITHUB_TOKEN=" > .env
`)

const CONFIG = require('./fixtures/config')
suite(pkg.name, () => {
  before(async () => {
    await fs.remove(CONFIG.outputDirectory)
  })

  test('Configure a statusboard instance', async () => {
    const board = await statusboard(CONFIG)
    assert.strictEqual(board.config.db, CONFIG.db)
    assert.strictEqual(board.config.outputDirectory, CONFIG.outputDirectory)
    assert.strictEqual(board.config.baseUrl, Config.defaults.baseUrl)
    assert.strictEqual(board.config.title, CONFIG.title)
    assert.strictEqual(board.config.description, CONFIG.description)

    assert.strictEqual(board.config.orgs.length, CONFIG.orgs.length)
    assert.strictEqual(board.config.orgs[0].name, CONFIG.orgs[0])

    assert.strictEqual(board.config.projects.length, CONFIG.projects.length)
github bookercodes / communitycasts.co / tests / index.js View on Github external
// @flow

import db from 'sequelize-connect'
import {expect} from 'chai'
import {suite, test, setup} from 'mocha';
import path from 'path'
import request from 'supertest-as-promised'
import app from '../source/app'
import config from 'config'

suite('index', () => {

  setup(function connectToAndResetTestDatabase() {
    db.logger.level = null
    db.discover = [path.join(__dirname, '../source/models')]
    db.matcher = function shouldImportModel(modelFileName) {
      return true
    }
    return db.connect(config.database, config.username, config.password, {
      force: true,
      logging: false
    })
  })

  test('POST without authorization header should return 401', async () => {
    const {statusCode} = await request(app)
    .post('/api/screencasts')
github gridgain / gridgain / modules / web-console / frontend / app / configuration / services / Clusters.spec.js View on Github external
* limitations under the License.
 */

import {suite, test} from 'mocha';
import {assert} from 'chai';
import {spy} from 'sinon';

import Provider from './Clusters';

const mocks = () => new Map([
    ['$http', {
        post: spy()
    }]
]);

suite('Clusters service', () => {
    test('discoveries', () => {
        const s = new Provider(...mocks().values());
        assert.isArray(s.discoveries, 'has discoveries array');
        assert.isOk(s.discoveries.every((d) => d.value && d.label), 'discoveries have correct format');
    });

    test('minMemoryPolicySize', () => {
        const s = new Provider(...mocks().values());
        assert.isNumber(s.minMemoryPolicySize, 'has minMemoryPolicySize number');
    });

    test('saveCluster', () => {
        const s = new Provider(...mocks().values());
        const cluster = {id: 1, name: 'Test'};
        s.saveCluster(cluster);
        assert.isOk(s.$http.post.called, 'calls $http.post');
github gridgain / gridgain / modules / web-console / frontend / app / configuration / services / ConfigurationResource.spec.js View on Github external
domains: [{
        _id: '1model',
        space: '1space',
        name: 'Test model',
        clusters: ['1cluster'],
        caches: ['1cache']
    }],
    igfss: [{
        _id: '1igfs',
        space: '1space',
        name: 'Test IGFS',
        clusters: ['1cluster']
    }]
};

suite('ConfigurationResourceTestsSuite', () => {
    test('ConfigurationResourceService correctly populate data', async() => {
        const service = configurationResource(null);
        const converted = _.cloneDeep(CHECKED_CONFIGURATION);
        const res = await service.populate(converted);

        assert.notEqual(res.clusters[0], converted.clusters[0]);

        assert.deepEqual(converted.clusters[0].caches, CHECKED_CONFIGURATION.clusters[0].caches);
        assert.deepEqual(converted.clusters[0].models, CHECKED_CONFIGURATION.clusters[0].models);
        assert.deepEqual(converted.clusters[0].igfss, CHECKED_CONFIGURATION.clusters[0].igfss);

        assert.deepEqual(converted.caches[0].clusters, CHECKED_CONFIGURATION.caches[0].clusters);
        assert.deepEqual(converted.caches[0].models, CHECKED_CONFIGURATION.caches[0].models);

        assert.deepEqual(converted.domains[0].clusters, CHECKED_CONFIGURATION.domains[0].clusters);
        assert.deepEqual(converted.domains[0].caches, CHECKED_CONFIGURATION.domains[0].caches);
github gridgain / gridgain / modules / web-console / frontend / app / configuration / store / reducer.spec.js View on Github external
import {suite, test} from 'mocha';
import {assert} from 'chai';

import {
    ADD_CLUSTER,
    REMOVE_CLUSTERS,
    UPDATE_CLUSTER,
    UPSERT_CLUSTERS,
    ADD_CACHE,
    UPDATE_CACHE,
    UPSERT_CACHES,
    REMOVE_CACHE,
    reducer
} from './reducer';

suite('page-configure component reducer', () => {
    test('Default state', () => {
        assert.deepEqual(
            reducer(void 0, {}),
            {
                clusters: new Map(),
                caches: new Map(),
                spaces: new Map()
            }
        );
    });

    test('ADD_CLUSTER action', () => {
        assert.deepEqual(
            reducer(
                {clusters: new Map([[1, {_id: 1}], [2, {_id: 2}]])},
                {type: ADD_CLUSTER, cluster: {_id: 3}}
github gridgain / gridgain / modules / web-console / frontend / app / configuration / components / page-configure-basic / reducer.spec.js View on Github external
* See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {suite, test} from 'mocha';
import {assert} from 'chai';

import {
    SET_CLUSTER,
    ADD_NEW_CACHE,
    REMOVE_CACHE,
    SET_SELECTED_CACHES,
    reducer
} from './reducer';

suite('page-configure-basic component reducer', () => {
    test('Default state', () => {
        assert.deepEqual(reducer(void 0, {}), {
            clusterID: -1,
            cluster: null,
            newClusterCaches: [],
            oldClusterCaches: []
        });
    });

    test('SET_CLUSTER action', () => {
        const root = {
            list: {
                clusters: new Map([[1, {name: 'New cluster', _id: 1, caches: [1]}]]),
                caches: new Map([[1, {}]]),
                spaces: new Map([[0, {}]])
            }
github gridgain / gridgain / modules / web-console / frontend / app / filters / bytes.filter.spec.js View on Github external
* 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import bytesFilter from './bytes.filter';

import { suite, test } from 'mocha';
import { assert } from 'chai';

const bytesFilterInstance = bytesFilter();

suite('bytes filter', () => {
    test('bytes filter', () => {
        assert.equal(bytesFilterInstance(0), '0 bytes');
        assert.equal(bytesFilterInstance(1000), '1000.0 bytes');
        assert.equal(bytesFilterInstance(1024), '1.0 kB');
        assert.equal(bytesFilterInstance(5000), '4.9 kB');
        assert.equal(bytesFilterInstance(1048576), '1.0 MB');
        assert.equal(bytesFilterInstance(104857600), '100.0 MB');
        assert.equal(bytesFilterInstance(1073741824), '1.0 GB');
        assert.equal(bytesFilterInstance(1099511627776), '1.0 TB');
    });
});
github gridgain / gridgain / modules / web-console / frontend / app / services / Clusters.spec.js View on Github external
* limitations under the License.
 */

import {suite, test} from 'mocha';
import {assert} from 'chai';
import {spy} from 'sinon';

import Provider from './Clusters';

const mocks = () => new Map([
    ['$http', {
        post: spy()
    }]
]);

suite('Clusters service', () => {
    test('discoveries', () => {
        const s = new Provider(...mocks().values());
        assert.isArray(s.discoveries, 'has discoveries array');
        assert.isOk(s.discoveries.every((d) => d.value && d.label), 'discoveries have correct format');
    });

    test('minMemoryPolicySize', () => {
        const s = new Provider(...mocks().values());
        assert.isNumber(s.minMemoryPolicySize, 'has minMemoryPolicySize number');
    });

    test('saveCluster', () => {
        const s = new Provider(...mocks().values());
        const cluster = {id: 1, name: 'Test'};
        s.saveCluster(cluster);
        assert.isOk(s.$http.post.called, 'calls $http.post');
github gridgain / gridgain / modules / web-console / frontend / app / components / grid-column-selector / controller.spec.js View on Github external
registerDataChangeCallback: spy(),
        processColumnsProcessors: spy((v) => Promise.resolve(v)),
        setVisibleColumns: spy((v) => Promise.resolve(v)),
        redrawInPlace: spy((v) => Promise.resolve(v)),
        refreshCanvas: spy((v) => Promise.resolve(v)),
        scrollTo: spy()
    },
    grouping: {
        on: {
            groupingChanged: spy()
        },
        getGrouping: stub().returns({grouping: []})
    }
});

suite('grid-column-selector component controller', () => {
    test('$onChanges', () => {
        const c = new Controller(...mocks().values());
        c.applyValues = spy(c.applyValues.bind(c));
        const api = apiMock();
        c.gridApi = api;
        c.$onChanges({gridApi: {currentValue: api}});

        assert.equal(c.applyValues.callCount, 1, 'calls applyValues');
        assert.isFunction(
            c.gridApi.grid.registerDataChangeCallback.lastCall.args[0]
        );

        c.gridApi.grid.registerDataChangeCallback.lastCall.args[0]();

        assert.equal(
            c.applyValues.callCount,