test("Taskr.constructor (defaults)", t => { const taskr = new Taskr() t.true(taskr instanceof Taskr, "returns a Taskr class") t.equal(taskr.file, undefined, "`taskr.file` is `undefined`") t.equal(taskr.root, process.cwd(), "`taskr.root` is `process.cwd()`") t.true($.isEmptyObj(taskr.tasks), "`taskr.tasks` is an empty object") t.true($.isEmptyObj(taskr.plugins), "`taskr.plugins` is an empty object") t.true(Array.isArray(taskr.plugNames), "`taskr.plugNames` is an array") t.true(taskr.plugNames.length === 0, "`taskr.plugNames` is empty") t.end() })
test("fn.toArray", t => { const fn = $.toArray t.deepEqual(fn([]), [], "keeps `[]` as is") t.deepEqual(fn(null), [], "converts `null` to empty array") t.deepEqual(fn(undefined), [], "converts `undefined` to empty array") t.deepEqual(fn(-1), [-1], "converts `-1` to `[-1]`") t.deepEqual(fn(0), [0], "converts `0` to `[0]`") t.deepEqual(fn(1), [1], "converts `1` to `[1]`") t.deepEqual(fn("foo"), ["foo"]) t.deepEqual(fn(["foo"]), ["foo"]) t.end() })
test("Taskr.constructor (exits)", t => { const fn = () => this.plugin("hello", {}, function * () {}) const plugins = { plugins: [fn] } const t1 = new Taskr({ plugins, tasks:['foo'] }) // test for `tasks_force_object` ? t1.on("tasks_force_object", () => console.log('HELLO?')) t.true(!t1.file && !t1.plugins, "exits EARLY if invalid `tasks` type") const t2 = new Taskr({ plugins }) t.true(t2.hasOwnProperty('file') && t2.hasOwnProperty('tasks'), "constructs shape") t.true($.isEmptyObj(t2.plugins), "stops before `plugins` loop if no `tasks` or `file`") t.end() })
test('@taskr/unflow (sourceMap:`external`)', t => { t.plan(1); create({ *foo(f) { const tmp = tmpDir('tmp-4'); yield f.source(`${dir}/*.js`).unflow({ sourceMap:'external' }).target(tmp); const str = yield f.$.read(`${tmp}/foo.js`, 'utf8'); t.true(/sourceMappingURL=foo.js.map/.test(str), 'attach an `external` sourceMap link'); yield f.clear(tmp); } }).start('foo'); });
test('@taskr/rev (all)', t => { t.plan(3); const taskr = create({ *foo(f) { t.true('rev' in taskr.plugins, 'attach `rev()` plugin to taskr'); t.true('revManifest' in taskr.plugins, 'attach `revManifest()` plugin to taskr'); t.true('revReplace' in taskr.plugins, 'attach `revReplace()` plugin to taskr'); } }); taskr.start('foo'); });
test('cli errors if legacy --local flag is set', function (t) { const cwd = tempy.directory() writeConfig(cwd, { providers: ['airtap-ignored-foo'], browsers: [{ name: 'test' }] }) exec(`node ${bin} --local test.js`, { env, cwd }, (err, stdout, stderr) => { t.ok(err, 'should error') t.is(stderr.trim(), read('no-local.txt').trim()) t.end() }) })
test('load config in eslint to validate all rule syntax is correct', function (t) { var CLIEngine = eslint.CLIEngine var cli = new CLIEngine({ useEslintrc: false, configFile: 'eslintrc.json' }) var code = 'var foo = 1\nvar bar = function () {}\nbar(foo)\n' t.equal(cli.executeOnText(code).errorCount, 0) t.end() })
test('@taskr/postcss', t => { t.plan(2); const taskr = create({ *foo(f) { t.true('postcss' in f, 'attach `postcss()` plugin to internal task'); } }); t.true('postcss' in taskr.plugins, 'attach `postcss()` plugin to taskr'); taskr.start('foo'); });
test('cli errors if provider does not exist', function (t) { const cwd = tempy.directory() writeConfig(cwd, { providers: ['airtap-non-existing-abc'], browsers: [{ name: 'test' }] }) exec(`node ${bin} test.js`, { env, cwd }, (err, stdout, stderr) => { t.ok(err, 'should error') t.ok(/cannot find module/i.test(stderr)) t.end() }) })
test('@taskr/stylus', t => { t.plan(1); const taskr = create({ *foo(f) { t.true('stylus' in taskr.plugins, 'attach `stylus()` plugin to taskr'); } }); taskr.start('foo'); });
test('@taskr/less', t => { t.plan(1); const taskr = create({ *foo(f) { t.true('less' in taskr.plugins, 'attach `less()` plugin to taskr'); } }); taskr.start('foo'); });