test('cli errors if no files are specified', function (t) { exec(`node ${bin}`, { env }, (err, stdout, stderr) => { t.ok(err, 'should error') t.is(stderr.trim(), 'At least one file must be specified.') t.end() }) })
tape("configBadFileSync", (test) => { test.plan(1); test.throws( function badFileCall() { markdownlint.readConfigSync("./test/config/config-badfile.json"); }, /ENOENT/, "Did not get correct exception for bad file." ); test.end(); });
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('cli errors if legacy --local and --open flags are set', function (t) { const cwd = tempy.directory() writeConfig(cwd, { providers: ['airtap-ignored-foo'], browsers: [{ name: 'test' }] }) exec(`node ${bin} --local --open test.js`, { env, cwd }, (err, stdout, stderr) => { t.ok(err, 'should error') t.is(stderr.trim(), read('no-local-open.txt').trim()) t.end() }) })
tape("configBadFile", (test) => { test.plan(4); markdownlint.readConfig("./test/config/config-badfile.json", function callback(err, result) { test.ok(err, "Did not get an error for bad file."); test.ok(err instanceof Error, "Error not instance of Error."); // @ts-ignore test.equal(err.code, "ENOENT", "Error code for bad file not ENOENT."); test.ok(!result, "Got result for bad file."); test.end(); }); });
test("cli.version", t => { const pkg = require("../package") const out = log(() => cli.version(pkg)) t.ok(out.length, "shows Taskr version") t.equal(out, `${pkg.name}, ${pkg.version}`, "shows correct version") t.end() })
tape("missingCallback", (test) => { test.plan(0); // @ts-ignore markdownlint(); test.end(); });
test("fn.flatten", t => { const fn = $.flatten t.deepEqual(fn(["a", "b", ["c"], "d", ["e"]]), ["a", "b", "c", "d", "e"], "flatten nested arrays") t.deepEqual(fn([[["a", ["b"]]], ["c"]]), ["a", "b", "c"], "flatten deeply nested arrays") t.end() })
tape("configSingleSync", (test) => { test.plan(1); const actual = markdownlint.readConfigSync("./test/config/config-child.json"); const expected = require("./config/config-child.json"); test.deepEqual(actual, expected, "Config object not correct."); test.end(); });
tape("configBadChildJson", (test) => { test.plan(3); markdownlint.readConfig("./test/config/config-badchildjson.json", function callback(err, result) { test.ok(err, "Did not get an error for bad child JSON."); test.ok(err instanceof Error, "Error not instance of Error."); test.ok(!result, "Got result for bad child JSON."); test.end(); }); });
tape("missingFilesAndStrings", (test) => { test.plan(2); markdownlint({}, function callback(err, result) { test.ifError(err); test.ok(result, "Did not get result for missing files/strings."); test.end(); }); });
tape("missingOptions", (test) => { test.plan(2); markdownlint(null, function callback(err, result) { test.ifError(err); test.deepEqual(result, {}, "Did not get empty result for missing options."); test.end(); }); });
tape("configBadChildJsonSync", (test) => { test.plan(1); test.throws( function badChildJsonCall() { markdownlint.readConfigSync("./test/config/config-badchildjson.json"); }, /Unable to parse '[^']*'; Unexpected token \S+ in JSON at position \d+/, "Did not get correct exception for bad child JSON." ); test.end(); });