Giter Site home page Giter Site logo

efueger / vuegister Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iatsiuk/vuegister

0.0 1.0 0.0 65 KB

Vuegister (an acronym for vue-register) is a require hook for loading of the Vue.js single-file components (or *.vue files).

License: MIT License

JavaScript 94.54% HTML 5.46%

vuegister's Introduction

vuegister npm version build status

About

Vuegister (an acronym for vue-register) is a require hook for loading of the Vue.js single-file components (or *.vue files). The main purpose of this package is to help the developer with unit testing of the component's logic. It allows you to import the object from the *.vue template as you do it with any Node.js module.

Sometimes you want to run multiple small tests simultaneously. Opening a new page with test suite in browser (even in PhantomJS) can take minutes. With the help of jsdom it is possible to speed up this process. You can run your unit tests in the pure Node.js environment. There is no need in heavy test runners (like Karma) or code transpilers (like Babel). Actual versions of Node.js supports new features from the latest revision of the JavaScript ECMA-262 specification. The website node.green provides overview of supported ECMAScript features in various versions of Node.js.

This package doesn't perform any transpiling of the code. Vuegister just extracts text between script tags, adds source map and passes the result to Module.prototype._compile. The module._compile method can only run JavaScript code (not CoffeeScript or Babel dependent). At the same time you can use external plugins for the code transpiling. Please see the Plugins section of this document.

Installation

npm i vuegister -D

Plugins

Vuegister can be easily extended through plugins to support various code preprocessors. Take a look at the babel plugin for further details.

Usage

Register *.vue extension from Node.js:

require('vuegister').register()

Using require hook from the Mocha test framework. This is equivalent to Babel’s babel-register:

mocha --require vuegister/register

Test suite example

To run test suite create test.js and MyComponent.vue files inside your test folder.

Content of the test.js file:

const assert = require('chai').assert;
const Vue = require('vue/dist/vue.common')
const MyComponent = require('./MyComponent.vue')

describe('MyComponent', () => {
  it('has a created hook', () => {
    assert.isFunction(MyComponent.created)
  })

  it('sets the correct default data', () => {
    assert.isFunction(MyComponent.data)
    const defaultData = MyComponent.data()
    assert.strictEqual(defaultData.message, 'hello!')
  })

  it('correctly sets the message when created', () => {
    const vm = new Vue(MyComponent).$mount()
    assert.strictEqual(vm.message, 'bye!')
  })
})

Content of the MyComponent.vue file:

<template>
  <span>{{ message }}</span>
</template>
<script>
  module.exports = {
    data () {
      return {
        message: 'hello!'
      }
    },
    created () {
      this.message = 'bye!'
    }
  }
</script>

Install jsdom-global and run tests with:

npm i jsdom jsdom-global -D
mocha -r jsdom-global/register -r vuegister/register

API Reference

Project documentation is generated automatically from source code. Please take a look at the api.md file in this repository.

Tests

To run the test suite, install development dependencies and execute:

npm run coverage

License

Distributed under MIT License.

vuegister's People

Contributors

iatsiuk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.