timrwood / moment-es6

MIT License
3 stars 0 forks source link

Port tests to es6 #1

Open timrwood opened 9 years ago

timrwood commented 9 years ago

Right now, we are using nodeunit to run tests in node + browsers.

In order to run tests, nodeunit will run any method on module.exports as a test.

exports.someTestName = function (test) {}

With the es6 module transpiler, we could define tests like so.

export function someTestName (test) {}

Nodeunit runs through every cjs module in a directory and runs the tests on its exports. This works pretty well, but I'm not sure how we will be able to iterate over all these files once they are transpiled in order to run them in the browser.

I'm wondering if we would need to switch to another test framework that isn't so node specific. QUnit perhaps?

Then, test files would look something more like so.

import { module, test, ok, equal } from "qunit";
import { moment } from "moment";

module("create");

test("from array", function () {});

Ideally, the lib + tests could be build into one file via broccoli and run in a browser and node without these browser*.js files.

Thoughts @trek?

trek commented 9 years ago

paging @rwjblue (he's our area expert around theses topics)

trek commented 9 years ago

Ideally, the lib + tests could be build into one file via broccoli and run in a browser and node without these browser*.js files.

Generally, I think that's the way to go. Write both tests and lib code using es6, transpile to amd, cjs, and globals[1]. Run amd and globals tests in a browser, run cjs tests via node. Broccoli seems like a good choice. There are a lot of es6->es5 module transpilers, but I've mostly used https://github.com/esnext/es6-module-transpiler. @eventualbuddha probably has good advice here?

[1] Although I know you want to move away from globals I feel obligated to lobby on their behalf for the huge community of JS developers for whom modules is a deep mystery. cc @searls

trek commented 9 years ago

And I'm not exactly a fan of QUnit, but it works very reliably.

timrwood commented 9 years ago

This is mostly done, just need to extract common locale tests.

Travis link here. https://travis-ci.org/timrwood/moment-es6

trek commented 9 years ago

Well, now the fun part: bikeshedding what the next public API should be!

timrwood commented 9 years ago

Well, after a huge refactoring this weekend, things are looking good.

Code is spread across ~80 small modules in the lib folder.

The bundled output is able to be tested using npm test, and the transpiled commonjs modules are able to be tested using npm run test-all.

Definitely still some work to be done refactoring and organizing files, but its-happening.gif.

eventualbuddha commented 9 years ago

@timrwood I'd recommend switching to either 6to5's module transpilation or, since you're using the bundle format, use http://esperantojs.org/ which has a better bundler than the es6-module-transpiler and is much faster.

timrwood commented 9 years ago

@eventualbuddha thanks for the tip, I wasn't aware of esperanto.