From 2443e35c188d41d2e2eb65827c8d7213a2c8952b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Rizio?= Date: Fri, 27 May 2016 22:46:19 +0200 Subject: [PATCH] Updates to latest i18next version (^3.1.0) and adds unit test. --- bower.json | 9 +- gulpfile.js | 231 +++++++++++++++++++---------------- package.json | 3 +- test/auto/base.html | 123 +++++++++++++++++++ test/auto/context.html | 100 +++++++++++++++ test/auto/interpolation.html | 81 ++++++++++++ test/auto/nesting.html | 68 +++++++++++ test/auto/plural.html | 108 ++++++++++++++++ wct.conf.json | 9 ++ 9 files changed, 626 insertions(+), 106 deletions(-) create mode 100644 test/auto/base.html create mode 100644 test/auto/context.html create mode 100644 test/auto/interpolation.html create mode 100644 test/auto/nesting.html create mode 100644 test/auto/plural.html create mode 100644 wct.conf.json diff --git a/bower.json b/bower.json index 310fb8e..a2c9119 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "kwc-i18next", - "version": "0.1.1", + "version": "0.1.3", "description": "A web component used to manage internationalization – replaces kwc-i18n", "license": "MIT", "main": "kwc-i18next.html", @@ -19,10 +19,13 @@ ], "dependencies": { "polymer": "Polymer/polymer#^1.0.0", - "i18next": "^2.5.1" + "i18next": "^3.1.0" }, "homepage": "https://github.com/successk/kwc-i18next", "authors": [ "Gaëtan Rizio " - ] + ], + "devDependencies": { + "i18next-xhr-backend": "^0.5.4" + } } diff --git a/gulpfile.js b/gulpfile.js index ee5f5dd..731cd98 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,53 +5,59 @@ const gutil = require("gulp-util"); const watch = require("gulp-watch"); const babel = require("gulp-babel"); const webserver = require("gulp-webserver"); -var uglify = require("gulp-uglify"); -var minifyInline = require("gulp-minify-inline"); -var htmlmin = require("gulp-htmlmin"); -var inlinesource = require("gulp-inline-source"); +const uglify = require("gulp-uglify"); +const minifyInline = require("gulp-minify-inline"); +const htmlmin = require("gulp-htmlmin"); +const inlinesource = require("gulp-inline-source"); +const wct = require("web-component-tester"); /// Constants const tasks = Object.freeze({ - devHTML: "compileHTML", - devSrcHTML: "devSrcHTML", - devDemoHTML: "devDemoHTML", - devJS: "compileJS", - devSrcJS: "devSrcJS", - devDemoJS: "devDemoJS", - devDemoJSON: "devDemoJSON", - devDependencies: "devDependencies", - dev: "dev", - - buildHTML: "buildHTML", - buildJS: "buildJS", + // Build + compileHtml: "compileHtml", + compileJs: "compileJs", inline: "inline", + + // Minify + minify: "minify", + minifyInline: "minifyInline", build: "build", - // used to check validity of built version - verifyBuild: "verifyBuild", - verifyDependencies: "verifyDependencies", - verifyDemoHTML: "verifyDemoHTML", - verifyDemoJS: "verifyDemoJS", - verifyDemoJSON: "verifyDemoJSON", - verify: "verify" + // Manual test + copyTestToTest: "copyTestToTest", + copyDependenciesToTest: "copyDependenciesToTest", + copyToTest: "copyToTest", + + // Demo + copyToDemo: "copyToDemo", + copyDependenciesToDemo: "copyDependenciesToDemo", + copyDemoToDemo: "copyDemoToDemo", + demo: "demo", + + // Tests + manualTest: "manualTest" }); const paths = Object.freeze({ + src: "src/**", srcHTML: "src/*.html", srcJS: "src/*.js", - demoHTML: "demo/**/*.html", - demoJS: "demo/**/*.js", - demoJSON: "demo/**/*.json", - - dev: "build/dev", - devComponent: "build/dev/" + bowerConfig.name, - devDemo: "build/dev/demo", build: "build/compile", - builtHTML: "build/compile/*.html", - - verifyDemo: "build/verify/demo", - verify: "build/verify" + buildHTML: "build/compile/*.html", + buildFiles: "build/compile/**", + + // Manual test files + testSrc: "test/**", + test: "build/test", + testComponent: "build/test/" + bowerConfig.name, + testTest: "build/test/test", + + // Demo files + demoSrc: "demo/**", + demo: "build/demo", + demoComponent: "build/demo/" + bowerConfig.name, + demoDemo: "build/demo/demo" }); /// Helpers @@ -60,108 +66,129 @@ function handleError(e) { this.emit("end"); } -function compileJS(source, dest) { - "use strict"; - return gulp.src(source) +/// Demo tasks +gulp.task(tasks.compileJs, () => + gulp.src(paths.srcJS) .pipe(babel({ presets: ["es2015"] })) .on("error", handleError) - .pipe(gulp.dest(dest)); -} - -function compileHTML(source, dest) { - "use strict"; - return gulp.src(source) - .on("error", handleError) - .pipe(gulp.dest(dest)); -} + .pipe(gulp.dest(paths.build)) +); -function dependencies(dest) { - "use strict"; - return gulp.src("bower_components/**/*") +gulp.task(tasks.compileHtml, () => + gulp.src(paths.srcHTML) .on("error", handleError) - .pipe(gulp.dest(dest)); -} - -/// Dev tasks -gulp.task(tasks.devSrcJS, () => compileJS(paths.srcJS, paths.devComponent)); + .pipe(gulp.dest(paths.build)) +); -gulp.task(tasks.devDemoJS, () => compileJS(paths.demoJS, paths.devDemo)); +gulp.task(tasks.inline, [tasks.compileHtml, tasks.compileJs], () => + gulp.src(paths.buildHTML) + .pipe(inlinesource()) + .pipe(gulp.dest(paths.build)) +); -gulp.task(tasks.devDemoJSON, () => gulp.src(paths.demoJSON).pipe(gulp.dest(paths.devDemo))); +gulp.task(tasks.minifyInline, [tasks.inline], () => + gulp.src(paths.buildHTML) + .pipe(minifyInline()) + .pipe(gulp.dest(paths.build)) +); -gulp.task(tasks.devSrcHTML, () => compileHTML(paths.srcHTML, paths.devComponent)); +gulp.task(tasks.minify, [tasks.minifyInline], () => + gulp.src(paths.buildHTML) + .pipe(htmlmin({collapseWhitespace: true})) + .pipe(gulp.dest(paths.build)) +); -gulp.task(tasks.devDemoHTML, () => compileHTML(paths.demoHTML, paths.devDemo)); +gulp.task(tasks.build, [tasks.minify], () => + gulp.src(paths.buildHTML) + .pipe(gulp.dest(".")) +); -gulp.task(tasks.devDependencies, () => dependencies(paths.dev)); +// Automatic tests +wct.gulp.init(gulp, [tasks.build]); -gulp.task(tasks.dev, [tasks.devSrcJS, tasks.devDemoJS, tasks.devDemoJSON, tasks.devSrcHTML, tasks.devDemoHTML, tasks.devDependencies], function () { - gulp.watch(paths.demoJS, [tasks.devDemoJS]); - gulp.watch(paths.demoJSON, [tasks.devDemoJSON]); - gulp.watch(paths.srcJS, [tasks.devSrcJS]); - gulp.watch(paths.demoHTML, [tasks.devDemoHTML]); - gulp.watch(paths.srcHTML, [tasks.devSrcHTML]); +// Manual tests +gulp.task(tasks.manualTest, [tasks.build], () => { + gulp.watch(paths.demoJS, [tasks.build]); + gulp.watch(paths.srcJS, [tasks.build]); + gulp.watch(paths.demoHTML, [tasks.build]); + gulp.watch(paths.srcHTML, [tasks.build]); - gulp.src(paths.dev) + gulp.src(".") .pipe(webserver({ host: "localhost", port: 8000, livereload: true, directoryListing: true, - open: "http://localhost:8000/demo" + open: "http://localhost:8000/test/manual" })); }); -/// Build tasks -gulp.task(tasks.buildHTML, () => - gulp.src(paths.srcHTML) - .pipe(minifyInline()) - .pipe(htmlmin({collapseWhitespace: true})) - .pipe(gulp.dest(paths.build)) -); +// Manual tests +gulp.task(tasks.copyTestToTest, () => { + return gulp.src(paths.testSrc) + .on("error", handleError) + .pipe(gulp.dest(paths.testTest)); +}); -gulp.task(tasks.buildJS, () => - gulp.src(paths.srcJS) - .pipe(babel({ - presets: ["es2015"] - })) - .pipe(uglify()) - .pipe(gulp.dest(paths.build)) +gulp.task(tasks.copyDependenciesToTest, () => + gulp.src("bower_components/**/*") + .on("error", handleError) + .pipe(gulp.dest(paths.test)) ); -gulp.task(tasks.inline, [tasks.buildHTML, tasks.buildJS], () => - gulp.src(paths.builtHTML) - .pipe(inlinesource()) - .pipe(gulp.dest(paths.build)) +gulp.task(tasks.copyToTest, [tasks.compileHtml, tasks.compileJs], () => + gulp.src(paths.buildFiles) + .on("error", handleError) + .pipe(gulp.dest(paths.testComponent)) ); -gulp.task(tasks.build, [tasks.inline], () => - gulp.src(paths.builtHTML) - .pipe(gulp.dest(".")) -); +gulp.task(tasks.manualTest, [tasks.copyToTest, tasks.copyTestToTest, tasks.copyDependenciesToTest], () => { + const dep = [tasks.copyToTest, tasks.copyTestToTest, tasks.copyDependenciesToTest]; + gulp.watch(paths.src, dep); + gulp.watch(paths.testSrc, dep); -gulp.task(tasks.verifyBuild, [tasks.build], () => - gulp.src("./*.html") - .pipe(gulp.dest("bower_components/" + bowerConfig.name)) -); + gulp.src(paths.test) + .pipe(webserver({ + host: "localhost", + port: 8000, + livereload: true, + directoryListing: true, + open: "http://localhost:8000/test/manual" + })); +}); -gulp.task(tasks.verifyDependencies, [tasks.verifyBuild], () => dependencies(paths.verify)); +// Demo +gulp.task(tasks.copyDemoToDemo, () => { + return gulp.src(paths.demoSrc) + .on("error", handleError) + .pipe(gulp.dest(paths.demoDemo)); +}); -gulp.task(tasks.verifyDemoJS, () => compileJS(paths.demoJS, paths.verifyDemo)); +gulp.task(tasks.copyDependenciesToDemo, () => + gulp.src("bower_components/**/*") + .on("error", handleError) + .pipe(gulp.dest(paths.demo)) +); -gulp.task(tasks.verifyDemoJSON, () => gulp.src(paths.demoJSON).pipe(gulp.dest(paths.verifyDemo))); +gulp.task(tasks.copyToDemo, [tasks.build], () => + gulp.src(paths.buildHTML) + .on("error", handleError) + .pipe(gulp.dest(paths.demoComponent)) +); -gulp.task(tasks.verifyDemoHTML, () => compileHTML(paths.demoHTML, paths.verifyDemo)); +gulp.task(tasks.demo, [tasks.copyToDemo, tasks.copyDemoToDemo, tasks.copyDependenciesToDemo], () => { + const dep = [tasks.copyToDemo, tasks.copyDemoToDemo, tasks.copyDependenciesToDemo] + gulp.watch(paths.src, dep); + gulp.watch(paths.demoSrc, dep); -gulp.task(tasks.verify, [tasks.verifyDependencies, tasks.verifyDemoJS, tasks.verifyDemoJSON, tasks.verifyDemoHTML], () => - gulp.src(paths.verify) + gulp.src(paths.demo) .pipe(webserver({ host: "localhost", port: 8000, - livereload: false, + livereload: true, directoryListing: true, open: "http://localhost:8000/demo" - })) -); \ No newline at end of file + })); +}); \ No newline at end of file diff --git a/package.json b/package.json index 21f0a1b..d4020bf 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "gulp-uglify": "^1.5.3", "gulp-util": "^3.0.7", "gulp-watch": "^4.3.5", - "gulp-webserver": "^0.9.1" + "gulp-webserver": "^0.9.1", + "web-component-tester": "^4.2.2" } } diff --git a/test/auto/base.html b/test/auto/base.html new file mode 100644 index 0000000..cf88ad2 --- /dev/null +++ b/test/auto/base.html @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/auto/context.html b/test/auto/context.html new file mode 100644 index 0000000..110cd1a --- /dev/null +++ b/test/auto/context.html @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/auto/interpolation.html b/test/auto/interpolation.html new file mode 100644 index 0000000..650ebbc --- /dev/null +++ b/test/auto/interpolation.html @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/auto/nesting.html b/test/auto/nesting.html new file mode 100644 index 0000000..cf68e0e --- /dev/null +++ b/test/auto/nesting.html @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/auto/plural.html b/test/auto/plural.html new file mode 100644 index 0000000..dce6e7d --- /dev/null +++ b/test/auto/plural.html @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wct.conf.json b/wct.conf.json new file mode 100644 index 0000000..441844a --- /dev/null +++ b/wct.conf.json @@ -0,0 +1,9 @@ +{ + "verbose": false, + "suites": ["test/auto"], + "plugins": { + "local": { + "browsers": ["firefox", "chrome"] + } + } +} \ No newline at end of file