Best JavaScript code snippet using ava
gruntfile.js
Source:gruntfile.js
1'use strict';2module.exports = function(grunt) {3 // Unified Watch Object4 var watchFiles = {5 serverViews: ['app/views/**/*.*'],6 serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js', '!app/tests/'],7 clientViews: ['public/modules/**/views/**/*.html'],8 clientJS: ['public/js/*.js', 'public/modules/**/*.js'],9 clientCSS: ['public/modules/**/*.css'],10 mochaTests: ['app/tests/**/*.js']11 };12 // Project Configuration13 grunt.initConfig({14 pkg: grunt.file.readJSON('package.json'),15 watch: {16 serverViews: {17 files: watchFiles.serverViews,18 options: {19 livereload: true20 }21 },22 serverJS: {23 files: watchFiles.serverJS,24 tasks: ['jshint'],25 options: {26 livereload: true27 }28 },29 clientViews: {30 files: watchFiles.clientViews,31 options: {32 livereload: true33 }34 },35 clientJS: {36 files: watchFiles.clientJS,37 tasks: ['jshint'],38 options: {39 livereload: true40 }41 },42 clientCSS: {43 files: watchFiles.clientCSS,44 tasks: ['csslint'],45 options: {46 livereload: true47 }48 },49 mochaTests: {50 files: watchFiles.mochaTests,51 tasks: ['test:server'],52 }53 },54 jshint: {55 all: {56 src: watchFiles.clientJS.concat(watchFiles.serverJS),57 options: {58 jshintrc: true59 }60 }61 },62 csslint: {63 options: {64 csslintrc: '.csslintrc'65 },66 all: {67 src: watchFiles.clientCSS68 }69 },70 uglify: {71 production: {72 options: {73 mangle: false74 },75 files: {76 'public/dist/application.min.js': 'public/dist/application.js'77 }78 }79 },80 cssmin: {81 combine: {82 files: {83 'public/dist/application.min.css': '<%= applicationCSSFiles %>'84 }85 }86 },87 nodemon: {88 dev: {89 script: 'server.js',90 options: {91 nodeArgs: ['--debug'],92 ext: 'js,html',93 watch: watchFiles.serverViews.concat(watchFiles.serverJS)94 }95 }96 },97 'node-inspector': {98 custom: {99 options: {100 'web-port': 1337,101 'web-host': 'localhost',102 'debug-port': 5858,103 'save-live-edit': true,104 'no-preload': true,105 'stack-trace-limit': 50,106 'hidden': []107 }108 }109 },110 ngAnnotate: {111 production: {112 files: {113 'public/dist/application.js': '<%= applicationJavaScriptFiles %>'114 }115 }116 },117 concurrent: {118 default: ['nodemon', 'watch'],119 debug: ['nodemon', 'watch', 'node-inspector'],120 options: {121 logConcurrentOutput: true,122 limit: 10123 }124 },125 env: {126 test: {127 NODE_ENV: 'test'128 },129 secure: {130 NODE_ENV: 'secure'131 }132 },133 mochaTest: {134 src: watchFiles.mochaTests,135 options: {136 reporter: 'spec',137 require: 'server.js'138 }139 },140 karma: {141 unit: {142 configFile: 'karma.conf.js'143 }144 }145 });146 // Load NPM tasks147 require('load-grunt-tasks')(grunt);148 // Making grunt default to force in order not to break the project.149 grunt.option('force', true);150 // A Task for loading the configuration object151 grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {152 var init = require('./config/init')();153 var config = require('./config/config');154 grunt.config.set('applicationJavaScriptFiles', config.assets.js);155 grunt.config.set('applicationCSSFiles', config.assets.css);156 });157 // Default task(s).158 grunt.registerTask('default', ['lint', 'concurrent:default']);159 // Debug task.160 grunt.registerTask('debug', ['lint', 'concurrent:debug']);161 // Secure task(s).162 grunt.registerTask('secure', ['env:secure', 'lint', 'concurrent:default']);163 // Lint task(s).164 grunt.registerTask('lint', ['jshint', 'csslint']);165 // Build task(s).166 grunt.registerTask('build', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'cssmin']);167 // Test task.168 grunt.registerTask('test', ['test:server', 'test:client']);169 grunt.registerTask('test:server', ['env:test', 'mochaTest']);170 grunt.registerTask('test:client', ['env:test', 'karma:unit']);...
gulpfile.js
Source:gulpfile.js
1'use strict';2var config = require('./config/config');3var del = require('del'),4 gulp = require('gulp'),5 mainBowerFiles = require('main-bower-files'),6 templateCache = require('gulp-angular-templatecache'),7 jshint = require('gulp-jshint'),8 concat = require('gulp-concat'),9 ngAnnotate = require('gulp-ng-annotate'),10 sass = require('gulp-sass'),11 sourcemap = require('gulp-sourcemaps'),12 nodemon = require('gulp-nodemon'),13 uglify = require('gulp-uglify'),14 minifyCss = require('gulp-minify-css');15var watchFiles = {16 allFiles: './**/*',17 devDir: '.tmp/public/',18 buildDir: 'build/public/',19 assetsDir: './assets/',20 appDir: 'assets/app/',21 jsDir: 'assets/js/',22 sassDir: 'assets/scss/',23 cssDir: 'assets/css/',24 imageDir: 'assets/img/',25 appOutputFile: 'app.js',26 dependenciesOutputFile: 'dependencies.js',27 viewOutputFile: 'views.js',28 29 ignoreApp: '!./**/app{,/**}',30 ignoreDependencies: '!./**/dependencies{,/**}',31 ignoreViews: '!./**/views{,/**}',32 ignoreSass: '!./**/scss{,/**}',33 ignoreMarkdown: '!*.md',34 viewFiles: 'assets/views/**/*.html',35 appFiles: 'assets/app/**/*.js',36 sassFiles: 'assets/scss/**/*.scss',37 imageFiles: 'assets/img/**',38 dependencyFiles: 'assets/dependencies/**'39};40gulp.task('clean', function (cb) {41 del([ watchFiles.devDir, watchFiles.buildDir ], cb);42});43gulp.task('bower-files', function () {44 return gulp.src(mainBowerFiles())45 .pipe(concat(watchFiles.dependenciesOutputFile))46 .pipe(gulp.dest(watchFiles.jsDir));47});48gulp.task('templates', function () {49 return gulp.src(watchFiles.viewFiles)50 .pipe(templateCache({ filename: watchFiles.viewOutputFile }))51 .pipe(gulp.dest(watchFiles.jsDir));52});53gulp.task('app', function () {54 return gulp.src(watchFiles.appFiles)55 .pipe(jshint())56 .pipe(ngAnnotate())57 .pipe(concat(watchFiles.appOutputFile))58 .pipe(gulp.dest(watchFiles.jsDir));59});60gulp.task('styles', function () {61 return gulp.src(watchFiles.sassFiles)62 .pipe(sourcemap.init())63 .pipe(sass())64 .pipe(sourcemap.write())65 .pipe(gulp.dest(watchFiles.cssDir));66});67gulp.task('copy-dev', [ 'clean' ], function () {68 return gulp.src([69 watchFiles.allFiles,70 watchFiles.ignoreApp,71 watchFiles.ignoreSass,72 watchFiles.ignoreMarkdown,73 watchFiles.ignoreViews,74 watchFiles.ignoreDependencies75 ], {76 cwd: watchFiles.assetsDir77 })78 .pipe(gulp.dest(watchFiles.devDir));79});80gulp.task('copy-build', [ 'dev' ], function () {81 return gulp.src(watchFiles.devDir + '**')82 .pipe(gulp.dest(watchFiles.buildDir));83});84gulp.task('uglify', [ 'copy-build' ], function () {85 return gulp.src(watchFiles.buildDir + 'js/**')86 .pipe(uglify())87 .pipe(gulp.dest(watchFiles.buildDir + 'js/'));88});89gulp.task('minify-css', [ 'copy-build' ], function () {90 gulp.src(watchFiles.buildDir + 'css/**')91 .pipe(minifyCss())92 .pipe(gulp.dest(watchFiles.buildDir + 'css/'));93});94gulp.task('watch', function () {95 gulp.watch([ watchFiles.assetsDir + 'index.html' ], [ 'copy-dev' ]);96 gulp.watch([ watchFiles.appFiles ], [ 'app', 'copy-dev' ]);97 gulp.watch([ watchFiles.viewFiles ], [ 'templates', 'copy-dev' ]);98 gulp.watch([ watchFiles.sassFiles ], [ 'styles', 'copy-dev' ]);99 gulp.watch([ watchFiles.imageFiles ], [ 'copy-dev' ]);100 gulp.watch([ watchFiles.dependencyFiles ], [ 'bower-files', 'copy-dev' ]);101});102gulp.task('dev', [103 'clean',104 'templates',105 'bower-files',106 'app',107 'styles',108 'copy-dev'109]);110gulp.task('build', [111 'uglify',112 'minify-css'113]);114gulp.task('serve', [ 'dev', 'watch' ], function () {115 nodemon({116 script: 'server.js',117 ext: 'js html',118 env: {119 port: config.server.port,120 callback: function (nodemon) {121 nodemon.on('log', function (event) {122 console.log(event.colour);123 });124 }125 }126 });...
Using AI Code Generation
1test('watchFiles', t => {2 const watcher = watchFiles(['test.js'], {3 });4 watcher.on('ready', () => {5 watcher.close();6 t.pass();7 });8});
Using AI Code Generation
1import test from 'ava';2import {watchFiles} from 'ava/lib/cli';3const files = ['test.js'];4watchFiles(files);5{6 "scripts": {7 }8}9{10 "scripts": {11 },12 "dependencies": {13 }14}15{16 "scripts": {17 },18 "dependencies": {19 }20}21{22 "scripts": {23 },24 "dependencies": {25 }26}27{28 "scripts": {29 },30 "dependencies": {31 }32}33{34 "scripts": {35 },36 "dependencies": {37 }38}39{40 "scripts": {41 },42 "dependencies": {43 }44}
Using AI Code Generation
1const test = require('ava');2const fs = require('fs');3test('watchFiles', t => {4 t.plan(1);5 t.true(fs.existsSync('test.js'));6});7const test = require('ava');8const fs = require('fs');9test('watch', t => {10 t.plan(1);11 t.true(fs.existsSync('test.js'));12});13const test = require('ava');14const fs = require('fs');15test('watch', t => {16 t.plan(1);17 t.true(fs.existsSync('test.js'));18});19const test = require('ava');20const fs = require('fs');21test('watch', t => {22 t.plan(1);23 t.true(fs.existsSync('test.js'));24});25const test = require('ava');26const fs = require('fs');27test('watch', t => {28 t.plan(1);29 t.true(fs.existsSync('test.js'));30});31const test = require('ava');32const fs = require('fs');33test('watch', t => {34 t.plan(1);35 t.true(fs.existsSync('test.js'));36});37const test = require('ava');38const fs = require('fs');39test('watch', t => {40 t.plan(1);41 t.true(fs.existsSync('test.js'));42});43const test = require('ava');44const fs = require('fs');45test('watch', t => {46 t.plan(1);47 t.true(fs.existsSync('test.js'));48});49const test = require('ava');50const fs = require('fs');51test('watch', t => {52 t.plan(1);53 t.true(fs.existsSync('test.js'));54});55const test = require('ava');56const fs = require('fs');57test('watch', t => {58 t.plan(1);
Using AI Code Generation
1test('watchFiles', t => {2 t.plan(2);3 t.watchFiles('test.js');4 t.is(1, 1);5});6test('watchFiles', t => {7 t.plan(2);8 t.watchFiles('test.js');9 t.is(1, 1);10});11test('watchFiles', t => {12 t.plan(2);13 t.watchFiles('test.js');14 t.is(1, 1);15});16test('watchFiles', t => {17 t.plan(2);18 t.watchFiles('test.js');19 t.is(1, 1);20});21test('watchFiles', t => {22 t.plan(2);23 t.watchFiles('test.js');24 t.is(1, 1);25});26test('watchFiles', t => {27 t.plan(2);28 t.watchFiles('test.js');29 t.is(1, 1);30});31test('watchFiles', t => {32 t.plan(2);33 t.watchFiles('test.js');34 t.is(1, 1);35});36test('watchFiles', t => {37 t.plan(2);38 t.watchFiles('test.js');39 t.is(1, 1);40});41test('watchFiles', t => {42 t.plan(2);43 t.watchFiles('test.js');44 t.is(1, 1);45});46test('watchFiles', t => {47 t.plan(2);48 t.watchFiles('test.js');49 t.is(1, 1);50});51test('watchFiles', t => {52 t.plan(2);
Using AI Code Generation
1import test from 'ava'2import { watchFiles } from 'ava/lib/cli'3import { resolve } from 'path'4const files = [resolve(__dirname, 'test/*')]5watchFiles(files)6import test from 'ava'7test('test', t => {8 t.pass()9})
Using AI Code Generation
1const test = require('ava');2const fs = require('fs');3test('Watch files', t => {4 fs.watchFile('test.js', (curr, prev) => {5 console.log('File changed');6 });7});
Using AI Code Generation
1var fs = require('fs');2var watchFiles = function(){3 fs.watchFile('./test.txt',function(curr,prev){4 console.log('the current mtime is: ' + curr.mtime);5 console.log('the previous mtime was: ' + prev.mtime);6 });7};8watchFiles();9var fs = require('fs');10var watchFiles = function(){11 fs.watch('./test.txt',function(event,filename){12 console.log('event is: ' + event);13 if(filename){14 console.log('filename provided: ' + filename);15 } else {16 console.log('filename not provided');17 }18 });19};20watchFiles();21var fs = require('fs');22var watchFiles = function(){23 fs.watchFile('./test.txt',function(curr,prev){24 console.log('the current mtime is: ' + curr.mtime);25 console.log('the previous mtime was: ' + prev.mtime);26 });27};28watchFiles();29var fs = require('fs');30var watchFiles = function(){31 fs.unwatchFile('./test.txt',function(curr,prev){32 console.log('the current mtime is: ' + curr.mtime);33 console.log('the previous mtime was: ' + prev.mtime);34 });35};36watchFiles();37var fs = require('fs');38var readStream = fs.createReadStream('./test.txt','utf8');39readStream.on('data',function(chunk){40 console.log('new chunk received:');41 console.log(chunk);42});43var fs = require('fs');44var writeStream = fs.createWriteStream('./test.txt','utf8');45writeStream.write('hello world');46writeStream.end();47var fs = require('fs');
Using AI Code Generation
1var watcher = availableWatchers.getWatcher();2var files = watcher.watchFiles();3console.log(files);4var watcher = availableWatchers.getWatcher();5watcher.watchFiles();6watcher.on('filewatcherwatchlistchanged', function(added, removed) {7 console.log(added);8 console.log(removed);9});10var watcher = availableWatchers.getWatcher();11watcher.watchFiles();12watcher.on('filewatcherfilechanged', function(file, changedTo) {13 console.log(file);14 console.log(changedTo);15});16var watcher = availableWatchers.getWatcher();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!