This repository has been archived by the owner on Nov 15, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chris Berthe
authored
May 10, 2017
1 parent
10682fe
commit 4c4e8a4
Showing
5 changed files
with
121 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import spawn from 'cross-spawn'; | ||
import debug from 'debug'; | ||
import config from '../config'; | ||
|
||
const logger = debug('slate-tools:test'); | ||
|
||
export default function(program) { | ||
program | ||
.command('test') | ||
.description('Runs translation tests for a theme\'s locale files (<theme>/src/locales/).') | ||
.action(() => { | ||
logger(`--gulpfile ${config.gulpFile}`); | ||
logger(`--cwd ${config.themeRoot}`); | ||
|
||
spawn(config.gulp, ['test', '--gulpfile', config.gulpFile, '--cwd', config.themeRoot], { | ||
detached: false, | ||
stdio: 'inherit', | ||
}); | ||
}); | ||
} |
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,60 @@ | ||
const gutil = require('gulp-util'); | ||
const _ = require('lodash'); | ||
|
||
/** Class representing a custom reporter for @shopify/theme-lint */ | ||
export default class Reporter { | ||
constructor() { | ||
this.successes = []; | ||
this.failures = []; | ||
} | ||
|
||
/** | ||
* Pushes a valid message onto successes. | ||
* | ||
* @param {String} message | ||
* @param {String} file | ||
*/ | ||
success(message, file = null, index = null) { | ||
this.successes.push([message, file, index]); | ||
} | ||
|
||
/** | ||
* Pushes an invalid message onto failures. | ||
* | ||
* @param {String} message | ||
* @param {String} file | ||
*/ | ||
failure(message, file = null, index = null) { | ||
this.failures.push([message, file, index]); | ||
} | ||
|
||
/** | ||
* Builds string output for translation tests | ||
* depending on successes and failures. | ||
*/ | ||
output() { | ||
const testsRun = this.failures.length + this.successes.length; | ||
|
||
if (this.failures.length === 0) { | ||
gutil.log('Translation tests complete:', | ||
gutil.colors.green(`Success (${testsRun} checks run)`), | ||
); | ||
} else { | ||
gutil.log('Translation tests complete:', | ||
gutil.colors.red(`Failed (${testsRun} checks run)`), | ||
); | ||
|
||
const failureGroups = _.groupBy(this.failures, (failure) => failure[1]); | ||
|
||
_.forOwn(failureGroups, (failures, file) => { | ||
gutil.log(gutil.colors.red(`${file}:`)); | ||
|
||
failures.map((failure) => { | ||
return gutil.log(failure[0]); | ||
}); | ||
}); | ||
} | ||
|
||
this.successes = this.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const gulp = require('gulp'); | ||
const {runAll} = require('@shopify/theme-lint'); | ||
|
||
const config = require('./includes/config.js'); | ||
const Reporter = require('./includes/lint-reporter.js').default; | ||
|
||
/** | ||
* Runs all the translation tests and the reporter outputs | ||
* the locale results once completed. | ||
* | ||
* @returns {String} Finalized linting output | ||
* @private | ||
*/ | ||
function lintLocales() { | ||
return runAll(config.src.root, new Reporter()).then((reporter) => { | ||
return reporter.output(); | ||
}); | ||
} | ||
|
||
/** | ||
* Runs translation tests using @shopify/theme-lint | ||
* | ||
* @function lint:locales | ||
* @memberof slate-cli.tasks.lint | ||
* @static | ||
*/ | ||
gulp.task('lint:locales', () => { | ||
return lintLocales(); | ||
}); |