Skip to content

Commit

Permalink
Chore: Reorganizing tests to align with project structure (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
platinumazure authored and nzakas committed Sep 27, 2016
1 parent 0b540e2 commit c19cd6d
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 109 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"repository": "eslint/generator-eslint",
"scripts": {
"test": "npm run lint && mocha",
"test": "npm run lint && mocha \"tests/**/*.js\"",
"lint": "eslint .",
"release": "eslint-release",
"ci-release": "eslint-ci-release",
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions test/test-main.js → tests/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("ESLint Main Generator", function() {
exec: this.spy
});

helpers.testDirectory(path.join(__dirname, "temp"), done);
helpers.testDirectory(path.join(__dirname, "../../temp"), done);
});

beforeEach(function() {
Expand All @@ -50,7 +50,7 @@ describe("ESLint Main Generator", function() {
*/

this.eslintGenerator = helpers.createGenerator("eslint", [
"../../app",
"../app",
[this.dummyGenerator, "eslint:plugin"]
]);

Expand Down Expand Up @@ -82,7 +82,7 @@ describe("ESLint Main Generator", function() {
*/

this.eslintGenerator = helpers.createGenerator("eslint", [
"../../app",
"../app",
[this.dummyGenerator, "eslint:rule"]
]);

Expand Down
2 changes: 1 addition & 1 deletion test/test-validation.js → tests/lib/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//------------------------------------------------------------------------------

var assert = require("assert");
var validators = require("../lib/validators");
var validators = require("../../lib/validators");

//------------------------------------------------------------------------------
// Tests
Expand Down
106 changes: 5 additions & 101 deletions test/test-creation.js → tests/plugin/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview Rule generator tests
* @fileoverview Plugin generator tests
* @author Nicholas C. Zakas
*/

Expand All @@ -11,121 +11,25 @@
// Requirements
//------------------------------------------------------------------------------

var fs = require("fs"),
path = require("path"),
var path = require("path"),
helpers = require("yeoman-test"),
assert = require("yeoman-assert");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

var testDirectory = path.join(__dirname, "temp");

describe("ESLint Rule Generator", function() {
beforeEach(function(done) {
helpers.testDirectory(testDirectory, function(err) {
if (err) {
return done(err);
}

this.rule = helpers.createGenerator("eslint:rule", [
"../../rule"
]);
return done();
}.bind(this));
});

it("creates expected files", function(done) {

var expected = [
"docs/rules/foo-bar.md",
"lib/rules/foo-bar.js",
"tests/lib/rules/foo-bar.js"
];

helpers.mockPrompt(this.rule, {
userName: "Foo Bar",
ruleId: "foo-bar",
desc: "My foo",
invalidCode: "var x;",
target: "eslint"
});
this.rule.options["skip-install"] = true;
this.rule.run(function() {
assert.file(expected);
done();
});
});

describe("With pathological input", function() {
describe("Double quotes in description", function() {
beforeEach(function(done) {
helpers.mockPrompt(this.rule, {
userName: "",
ruleId: "test-rule",
desc: "My \"foo\"",
invalidCode: "var x = \"foo\";",
target: "eslint"
});
this.rule.options["skip-install"] = true;
this.rule.run(done);
});

describe("Resulting rule file", function() {
beforeEach(function() {
this.resultRuleModule = require(path.join(testDirectory, "lib", "rules", "test-rule"));
});

it("should be requireable", function() {
assert.ok(this.resultRuleModule);
});

it("should have correct description", function() {
assert.strictEqual(this.resultRuleModule.meta.docs.description, "My \"foo\"");
});
});
});

describe("Double quotes in code snippet", function() {
beforeEach(function(done) {
helpers.mockPrompt(this.rule, {
userName: "",
ruleId: "test-rule",
desc: "My \"foo\"",
invalidCode: "var x = \"foo\";",
target: "eslint"
});
this.rule.options["skip-install"] = true;
this.rule.run(done);
});

describe("Resulting test file", function() {
beforeEach(function() {
this.resultTestModuleContent = fs.readFileSync(path.join(testDirectory, "tests", "lib", "rules", "test-rule.js"), "utf8");
});

it("should be readable", function() {
assert.ok(this.resultTestModuleContent);
});

it("should have correct code snippet", function() {
assert.ok(this.resultTestModuleContent.indexOf("code: \"var x = \\\"foo\\\";") > -1);
});
});
});
});
});
var testDirectory = path.join(__dirname, "../../temp");

describe("ESLint Plugin Generator", function() {
beforeEach(function(done) {
helpers.testDirectory(path.join(__dirname, "temp"), function(err) {
helpers.testDirectory(testDirectory, function(err) {
if (err) {
return done(err);
}

this.rule = helpers.createGenerator("eslint:plugin", [
"../../plugin"
"../plugin"
]);
return done();
}.bind(this));
Expand Down
118 changes: 118 additions & 0 deletions tests/rule/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* @fileoverview Rule generator tests
* @author Nicholas C. Zakas
*/

/* eslint no-invalid-this:0 */

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

var fs = require("fs"),
path = require("path"),
helpers = require("yeoman-test"),
assert = require("yeoman-assert");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

var testDirectory = path.join(__dirname, "../../temp");

describe("ESLint Rule Generator", function() {
beforeEach(function(done) {
helpers.testDirectory(testDirectory, function(err) {
if (err) {
return done(err);
}

this.rule = helpers.createGenerator("eslint:rule", [
"../rule"
]);
return done();
}.bind(this));
});

it("creates expected files", function(done) {

var expected = [
"docs/rules/foo-bar.md",
"lib/rules/foo-bar.js",
"tests/lib/rules/foo-bar.js"
];

helpers.mockPrompt(this.rule, {
userName: "Foo Bar",
ruleId: "foo-bar",
desc: "My foo",
invalidCode: "var x;",
target: "eslint"
});
this.rule.options["skip-install"] = true;
this.rule.run(function() {
assert.file(expected);
done();
});
});

describe("With pathological input", function() {
describe("Double quotes in description", function() {
beforeEach(function(done) {
helpers.mockPrompt(this.rule, {
userName: "",
ruleId: "test-rule",
desc: "My \"foo\"",
invalidCode: "var x = \"foo\";",
target: "eslint"
});
this.rule.options["skip-install"] = true;
this.rule.run(done);
});

describe("Resulting rule file", function() {
beforeEach(function() {
this.resultRuleModule = require(path.join(testDirectory, "lib", "rules", "test-rule"));
});

it("should be requireable", function() {
assert.ok(this.resultRuleModule);
});

it("should have correct description", function() {
assert.strictEqual(this.resultRuleModule.meta.docs.description, "My \"foo\"");
});
});
});

describe("Double quotes in code snippet", function() {
beforeEach(function(done) {
helpers.mockPrompt(this.rule, {
userName: "",
ruleId: "test-rule",
desc: "My \"foo\"",
invalidCode: "var x = \"foo\";",
target: "eslint"
});
this.rule.options["skip-install"] = true;
this.rule.run(done);
});

describe("Resulting test file", function() {
beforeEach(function() {
this.resultTestModuleContent = fs.readFileSync(path.join(testDirectory, "tests", "lib", "rules", "test-rule.js"), "utf8");
});

it("should be readable", function() {
assert.ok(this.resultTestModuleContent);
});

it("should have correct code snippet", function() {
assert.ok(this.resultTestModuleContent.indexOf("code: \"var x = \\\"foo\\\";") > -1);
});
});
});
});
});
4 changes: 1 addition & 3 deletions test/test-load.js → tests/test-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
* @author Nicholas C. Zakas
*/

/* eslint no-undefined:0 */

"use strict";

var assert = require("assert");

describe("eslint generator", function() {
it("can be imported without blowing up", function() {
var app = require("../rule");
assert(app !== undefined);
assert.ok(app);
});
});

0 comments on commit c19cd6d

Please sign in to comment.