This repository has been archived by the owner on May 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from helpscout/add-testing
Add testing
- Loading branch information
Showing
11 changed files
with
209 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ var help = ` | |
c, component | ||
o, object | ||
s, scope | ||
t, test | ||
u, utility | ||
Name: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Commands :: Test | ||
'use strict'; | ||
|
||
if (!global.cli.flags.test) { | ||
return false; | ||
} | ||
|
||
var _ = require('lodash'); | ||
var del = require('del'); | ||
var findRoot = require('find-root'); | ||
var fs = require('fs'); | ||
var glob = require('glob'); | ||
var mkdirp = require('mkdirp'); | ||
var path = require('path'); | ||
var uuid = require('node-uuid'); | ||
|
||
var Mocha = require('mocha'); | ||
var mocha = new Mocha(); | ||
var root = findRoot(process.cwd()); | ||
var templateFile = global.templateDir + 'test/index.js'; | ||
var template = fs.readFileSync(templateFile, 'utf8'); | ||
var testCache = root + '/.seed-test-cache'; | ||
var testDir = 'test'; | ||
|
||
var options = { | ||
ignore: [ | ||
'bower_components/**/*', | ||
'node_modules/**/*' | ||
] | ||
}; | ||
|
||
var clean = function() { | ||
return del(testCache, { force: true }); | ||
}; | ||
|
||
var getTestFileName = function(file) { | ||
return path.basename(file).replace(/_/g, '').replace('.scss', '') + '-' + uuid.v1() + '.js'; | ||
}; | ||
|
||
// Delete the test cache directory (just in case it was left over) | ||
clean(); | ||
|
||
glob('**/*.scss', options, function(err, matches) { | ||
var files = matches; | ||
var currentDir = process.cwd().split('/').pop(); | ||
|
||
if (currentDir !== testDir) { | ||
files = files.filter(function(file) { | ||
var dir = testDir + '/'; | ||
return file.indexOf(dir) >= 0; | ||
}); | ||
} | ||
// Create the test cache directory | ||
mkdirp.sync(testCache); | ||
|
||
if (!files.length) { | ||
console.log(`\nCouldn't find any tests in your project!`); | ||
console.log(`You can create a new test by executinexecuting "seed g"\n`); | ||
process.exit(0) | ||
} | ||
|
||
_.forEach(files, function(file) { | ||
var dest = testCache + '/' + getTestFileName(file); | ||
var options = { | ||
file: file | ||
}; | ||
// Add mocha compatible .js file to test cache | ||
fs.writeFileSync(dest, _.template(template)(options)); | ||
// Add path of test cache file to Mocha | ||
mocha.addFile(dest); | ||
}); | ||
|
||
mocha.run(function(failures){ | ||
// Delete test cache redirectory | ||
clean(); | ||
process.on('exit', function() { | ||
process.exit(failures); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var path = require('path'); | ||
var sassTrue = require('sass-true'); | ||
|
||
sassTrue.runSass({file: '<%= file %>'}, describe, it); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// <%= docName %> :: <%= docType %> | ||
|
||
@import "true"; | ||
|
||
@include test-module("<%= name %>") { | ||
|
||
@include test("Example .scss test (Generated by seed-cli)") { | ||
@include assert('pink') { | ||
|
||
$pink-hot: pink; | ||
@include output { | ||
background: $pink-hot; | ||
} | ||
|
||
@include expect { | ||
background: pink; | ||
} | ||
|
||
} | ||
} | ||
|
||
@include test("Another .scss test (Generated by seed-cli)") { | ||
|
||
$test: 0; | ||
$expect: 0; | ||
|
||
@include assert-equal($test, $expect, '0'); | ||
} | ||
} |