All Projects → apsdehal → qunit-migrate

apsdehal / qunit-migrate

Licence: MIT License
Migrate old QUnit tests to 2.x. Uses regex and ASTs to convert old QUnit code.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to qunit-migrate

Regex
A pure Swift NFA implementation of a regular expression engine
Stars: ✭ 27 (+58.82%)
Mutual labels:  regex
ast-builder
Build your ASTs directly from code
Stars: ✭ 18 (+5.88%)
Mutual labels:  ast
jsdast
JSDoc Abstract Syntax Tree
Stars: ✭ 20 (+17.65%)
Mutual labels:  ast
datagoose
🔐 Easy to use, fast, lightweight, secure, JSON based database for Python!
Stars: ✭ 13 (-23.53%)
Mutual labels:  regex
esvalid
confirm that a SpiderMonkey format AST represents an ECMAScript program
Stars: ✭ 24 (+41.18%)
Mutual labels:  ast
splinter
Simple pattern-based linter 🐀
Stars: ✭ 31 (+82.35%)
Mutual labels:  regex
mention-hashtag
Extract mentions (@mention) or hashtags (#hashtag) from any text
Stars: ✭ 16 (-5.88%)
Mutual labels:  regex
core
🌈 light, fast, and easy to use, dependencies free javascript syntax highlighter, with automatic language detection
Stars: ✭ 40 (+135.29%)
Mutual labels:  regex
tsquery-playground
Playground for TSQuery
Stars: ✭ 30 (+76.47%)
Mutual labels:  ast
Code2HTML
JavaFX tool for converting source code to styled HTML
Stars: ✭ 26 (+52.94%)
Mutual labels:  regex
extglob
Extended globs. Add (almost) the expressive power of regular expressions to glob patterns.
Stars: ✭ 25 (+47.06%)
Mutual labels:  regex
rustexp
A Rust regular expression editor and tester that runs entirely within the browser!
Stars: ✭ 59 (+247.06%)
Mutual labels:  regex
parseclj
Clojure Parser for Emacs Lisp
Stars: ✭ 44 (+158.82%)
Mutual labels:  ast
ast ninja
The Elixir AST explorer
Stars: ✭ 59 (+247.06%)
Mutual labels:  ast
zig-regex
A regex implementation for the zig programming language
Stars: ✭ 60 (+252.94%)
Mutual labels:  regex
astra
Astra: a Java tool for analysing and refactoring Java source code
Stars: ✭ 35 (+105.88%)
Mutual labels:  ast
valast
Convert Go values to their AST
Stars: ✭ 251 (+1376.47%)
Mutual labels:  ast
postcss-rs
🚀 Fast and 100% API compatible postcss replacer, built in Rust
Stars: ✭ 414 (+2335.29%)
Mutual labels:  ast
tydoc
The TypeScript documenter that meets you where you are
Stars: ✭ 28 (+64.71%)
Mutual labels:  ast
subst
Search and des... argh... replace in many files at once. Use regexp and power of Python to replace what you want.
Stars: ✭ 20 (+17.65%)
Mutual labels:  regex

QUnit Migrate

NPM Version Build Status

Migrate old QUnit code to 2.x.

Features

  • JSCS support
  • Custom config support for defining rules
  • Supports conversion of Async tests
  • Support for globbing patterns
  • Both regex and ast parser supported

Install

npm install --global qunit-migrate

Usage

  qunit-migrate -h

  Usage: qunit-migrate [options] <file ...>

  QUnit Migrate: A tool to migrate your files to QUnit 2.0 API

  Options:

    -h, --help                output usage information
    -V, --version             output the version number
    -c, --config <path>       Config file for qunit-migrate
    -P, --parser <regex|ast>  Parser to be used for parsing, Default: ast
    -w, --write               Pass if parsed files should be overwritten. Default: false
    -p, --preset <string>     Preset rule for jscs config. Default: jquery
    -j, --no-jscs             Pass if jscs fix should not be applied. Default: true

  Globbing is supported in files

  Examples:

    $ qunit-migrate "./**/*.js" -w --preset "google" -c "config.json"
    $ # This will migrate all js files in subdirectories using google
    $ # preset and config as config.json

Information: AST parser is more robust than regex parser

Configuration

Various rules can be toggled through use of custom config which can be passed via -c option.

Default config file

Sample config file

Config Rules

Example:

qunit-migrate tries to change old QUnit code to new QUnit specifications.

For e.g. following code will be converted as follows:

// Taken directly from jquery-globalize
// file1.js
define([
  "cldr",
  "src/core",
  "json!cldr-data/supplemental/likelySubtags.json",
  "cldr/event"
], function( Cldr, Globalize, likelySubtags ) {
Cldr.load( likelySubtags );
module( "Globalize.locale" );
ssyncTest( "should allow String locale", function() {
  stop();
  Globalize.locale( "en" );
  ok( Globalize.cldr instanceof Cldr );
  equal( Globalize.cldr.locale, "en" );
  start();
});
});

$ qunit-migrate "file1.js" -w

to

// Taken directly from jquery-globalize
// file1.js
define( [ 
  "qunit",
  "cldr",
  "src/core",
  "json!cldr-data/supplemental/likelySubtags.json",
  "cldr/event"
], function( QUnit, Cldr, Globalize, likelySubtags ) {
Cldr.load( likelySubtags );
QUnit.module( "Globalize.locale" );
QUnit.test( "should allow String locale", function( assert ) {
  var ready = assert.async();
  Globalize.locale( "en" );
  assert.ok( Globalize.cldr instanceof Cldr );
  assert.equal( Globalize.cldr.locale, "en" );
  ready();
});
});

API

$ npm install --save qunit-migrate

var qunitMigrate = require('qunit-migrate');
var qmAst = qunitMigrate.ast;
var qmRegex = qunitMigrate.regex;
var data = 'Some old qunit code';

var modifiedDataAST = qmAst(data); // Fixed code through AST
var modifiedDataRegex = qmRegex(data); // Fixed code through AST

Information: qunit-migrate api doesn't fix source with jscs

Accuracy & Limitations

QUnit migrate tries its best to upgrade your API, but there are still some limitations.

For e.g.

  • If you are encapsulating some of your logic in a function and using assertions in that, it is your responsibility to pass assert into function parameters. API of qunit-migrate can also be upgraded to do this, but it doesn't support it at the moment
  • There might be issues with require definitions some time if they are not in the start and encapsulated somewhere.
  • QUnit.reset is not supported as of now

All these are fixable through AST. Pull requests are welcome

License

MIT © Amanpreet Singh

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].