How to use japa - 10 common examples

To help you get started, we’ve selected a few japa 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 poppinss / indicative / test-old / parser.spec.js View on Github external
'use strict'

/**
 * indicative
 * Copyright(c) 2015-2015 Harminder Virk
 * MIT Licensed
*/

const test = require('japa')
const Parser = require('../src/Parser')
const Rule = require('../src/Rule')

test.group('Parser', function () {
  // ////////////////
  // test suite 1 //
  // ////////////////
  test('should parse a rule and convert it into an object', function (assert) {
    const rules = {
      name: 'required'
    }

    const parsedRules = {
      name: [{
        name: 'required',
        args: []
      }]
    }
    const parsed = {name: Parser.parse(rules.name)}
    assert.deepEqual(parsed, parsedRules)
github rhwilr / adonis-bumblebee / test / commands.spec.js View on Github external
*
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

const fs = require('fs-extra')
const test = require('japa')
const path = require('path')
const ace = require('@adonisjs/ace')

const setup = require('./setup')
const MakeTransformer = require('../src/Commands/MakeTransformer')
const originalConsoleLog = console.log
const originalConsoleError = console.error

test.group('Commands', group => {
  let lastLogged
  const transformerFilePath = path.join(__dirname, '../app/Transformers/TestTransformer.js')
  const transformerFileWithSubdirectoryPath = path.join(__dirname, '../app/Transformers/Dir/TestTransformer.js')

  group.before(async () => {
    await setup()
    console.log = console.error = (string) => { lastLogged = string }
  })

  group.afterEach(() => {
    // cleanup
    try {
      fs.unlinkSync(transformerFilePath)
      fs.unlinkSync(transformerFileWithSubdirectoryPath)
      fs.rmdirSync(path.join(__dirname, '../app/Transformers/Dir/'))
      fs.rmdirSync(path.join(__dirname, '../app/Transformers/'))
github Slynova-Org / fence / tests / unit / helpers.spec.js View on Github external
const test = require('japa')
const post = require('../stubs/post.json')
const { formatResourceName } = require('../../dist/Helpers')
const PostClass = require('../stubs/Post')

test.group('Helpers', (group) => {

  test('it should format correctly the resource name', (assert) => {
    assert.equal(formatResourceName(post), 'Post')
    assert.equal(formatResourceName(PostClass), 'Post')
    assert.equal(formatResourceName(new PostClass()), 'Post')
  })

})
github nrempel / adonis-scheduler / test / scheduler.spec.js View on Github external
'use strict'

const path = require('path')
const test = require('japa')
const { ioc } = require('@adonisjs/fold')
const { Helpers, Logger } = require('@adonisjs/sink')
const Scheduler = require('../src/Scheduler')

test.group('Scheduler', (group) => {
  /**
   * @param {String} name
   * @return {Helpers}
   */
  function getHelpers (name) {
    ioc.fake('Adonis/Src/Helpers', () => new Helpers(path.join(__dirname, `./projects/${name}`)))
    return ioc.use('Adonis/Src/Helpers')
  }

  group.before(() => {
    ioc.fake('Task', () => require('./../src/Scheduler/Task'))
    ioc.fake('Adonis/Src/Logger', () => new Logger())
  })

  test('Should instantiate correctly', (assert) => {
    const Helpers = getHelpers('good')
github Slynova-Org / fence / tests / unit / gate.spec.js View on Github external
const test = require('japa')
const Post = require('../stubs/Post')
const post = require('../stubs/post.json')
const PostPolicy = require('../stubs/PostPolicy')
const { Gate } = require('../../dist/Gate')
const { Storage } = require('../../dist/Storage')

const storage = Storage.instance

test.group('Gate', (group) => {
  group.beforeEach(() => {
    storage.$reset()
  })

  test('it should be able to define gate', (assert) => {
    Gate.define('test-gate', () => {})

    assert.equal(Object.keys(storage.$gates).length, 1)
    assert.isDefined(storage.$gates['test-gate'])
  })

  test('it should be able to define multiple gates', (assert) => {
    Gate.define('test-gate', () => {})
    Gate.define('test-gate2', () => {})

    assert.equal(Object.keys(storage.$gates).length, 2)
github juampi92 / adonis-mongoose-model / test / hooks_transform.spec.js View on Github external
'use strict'

const test = require('japa')
const utils = require('../src/utils')

test.group('Hooks', function () {
  test('should separate correctly to mongoose', function (assert) {
    const events = {
      preSave: { instruction: 'pre', command: 'save' },
      postSave: { instruction: 'post', command: 'save' },
      preFind: { instruction: 'pre', command: 'find' }
    }

    Object.keys(events).forEach(key => {
      assert.deepEqual(utils.formatToMongooseMiddleware(key), events[key])
    })
  })

  test('should throw error when invalid', function (assert) {
    assert.throws(() => utils.formatToMongooseMiddleware('preSaved'),
      'saved is not a valid mongoose command when using preSaved. Check the middleware docs: http://mongoosejs.com/docs/middleware.html')
github adonisjs / adonis-lucid / test / unit / hooks.spec.js View on Github external
* adonis-lucid
 *
 * (c) Harminder Virk 
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

const test = require('japa')
const { ioc } = require('@adonisjs/fold')
const { setupResolver } = require('@adonisjs/sink')

const Hooks = require('../../src/Lucid/Hooks')
const helpers = require('./helpers')

test.group('Hooks', (group) => {
  group.before(() => {
    setupResolver()
  })

  group.beforeEach(() => {
    ioc.restore()
  })

  test('it should add handler for a hook', (assert) => {
    const hooks = new Hooks()
    const fn = function () {}
    hooks.addHandler('create', fn)
    assert.deepEqual(hooks._handlers, { create: [{ handler: fn, name: undefined }] })
  })

  test('it should add named handler for a hook', (assert) => {
github duyluonglc / lucid-mongo / test / unit / hooks.spec.js View on Github external
*
 * (c) Harminder Virk 
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

require('../../lib/iocResolver').setFold(require('@adonisjs/fold'))
const test = require('japa')
const { ioc } = require('@adonisjs/fold')
const { setupResolver } = require('@adonisjs/sink')

const Hooks = require('../../src/LucidMongo/Hooks')
const helpers = require('./helpers')

test.group('Hooks', (group) => {
  group.before(() => {
    setupResolver()
  })

  group.beforeEach(() => {
    ioc.restore()
  })

  test('it should add handler for a hook', (assert) => {
    const hooks = new Hooks()
    const fn = function () { }
    hooks.addHandler('create', fn)
    assert.deepEqual(hooks._handlers, { create: [{ handler: fn, name: undefined }] })
  })

  test('it should add named handler for a hook', (assert) => {
github adonisjs / adonis-mail / test / mail.spec.js View on Github external
/*
 * adonis-mail
 *
 * (c) Harminder Virk 
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

const test = require('japa')
const { Config } = require('@adonisjs/sink')
const Mail = require('../src/Mail')
const { smtp: SmtpDriver } = require('../src/Mail/Drivers')

test.group('Mail', () => {
  test('throw exception when unable to find mail connection', (assert) => {
    const config = new Config()
    const mail = new Mail(config)
    const fn = () => mail.connection()
    assert.throw(fn, 'E_INVALID_PARAMETER: Make sure to define connection inside config/mail.js file')
  })

  test('throw exception connection config is missing', (assert) => {
    const config = new Config()
    config.set('mail.connection', 'smtp')
    const mail = new Mail(config)
    const fn = () => mail.connection()
    assert.throw(fn, 'E_MISSING_CONFIG: smtp is not defined inside config/mail.js file')
  })

  test('throw exception when driver is not defined on connection', (assert) => {
github adonisjs / ace / test / parser.spec.js View on Github external
'use strict'

/**
 * adonis-ace
 *
 * (c) Harminder Virk 
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
*/

const test = require('japa')
const Parser = require('../src/Parser')

test.group('Parser', function () {
  test('should parse signature to find command arguments', function (assert) {
    const parsed = Parser.parseSignature('{name} {age}')
    assert.isArray(parsed.args)
    assert.lengthOf(parsed.args, 2)
  })

  test('should parse signature to find command options', function (assert) {
    const parsed = Parser.parseSignature('{name} {--age}')
    assert.isArray(parsed.args)
    assert.lengthOf(parsed.args, 1)
    assert.isArray(parsed.options)
    assert.lengthOf(parsed.options, 1)
  })

  test('should parse signature to fing options with aliases', function (assert) {
    const parsed = Parser.parseSignature('{name} {-a, --age}')

japa

Lean test runner for Node.js

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular japa functions