Minify: Move some testing helpers into a module

Created on 2 Aug 2016  路  5Comments  路  Source: babel/minify

Might be a little less setup?
Something like (maybe need to split up or move arguments around):
Basically always unpad, trim

const babel = require("babel-core");
const unpad = require("utils/unpad");

export function transform(source, plugin, options) {
  return babel.transform(unpad(source),  {
    plugins: [[plugin, options]],
  }).code.trim();
}

export function expectTransform(source, expected, plugin, options = {}) {
  return expect(transform(source, plugin, options)).toBe(unpad(expected));
}
Chore

Most helpful comment

Jest snapshots work with any serializable value, we just haven't documented it yet. This is actually the ideal use case for snapshots and should allow you guys to move much faster. Also cc @kyldvs who loves using it for strings.

All 5 comments

Good idea.

Also, since we are always checking transformed input to static output, it would make sense to add toMatchSnapshot feature of jest, and we don't have to maintain a separate expected value at all.

I'm not sure if we can use it for any content - though in the docs it says React Component.

cc @cpojer?

Jest snapshots work with any serializable value, we just haven't documented it yet. This is actually the ideal use case for snapshots and should allow you guys to move much faster. Also cc @kyldvs who loves using it for strings.

Added in #606 . :)

Was this page helpful?
0 / 5 - 0 ratings