Best JavaScript code snippet using ava
test-statusMatrix.js
Source:test-statusMatrix.js
1/* eslint-env node, browser, jasmine */2const path = require('path')3const { statusMatrix, add, remove } = require('isomorphic-git')4const { makeFixture } = require('./__helpers__/FixtureFS.js')5describe('statusMatrix', () => {6 it('statusMatrix', async () => {7 // Setup8 const { fs, dir, gitdir } = await makeFixture('test-statusMatrix')9 // Test10 let matrix = await statusMatrix({ fs, dir, gitdir })11 expect(matrix).toEqual([12 ['a.txt', 1, 1, 1],13 ['b.txt', 1, 2, 1],14 ['c.txt', 1, 0, 1],15 ['d.txt', 0, 2, 0],16 ])17 await add({ fs, dir, gitdir, filepath: 'a.txt' })18 await add({ fs, dir, gitdir, filepath: 'b.txt' })19 await remove({ fs, dir, gitdir, filepath: 'c.txt' })20 await add({ fs, dir, gitdir, filepath: 'd.txt' })21 matrix = await statusMatrix({ fs, dir, gitdir })22 expect(matrix).toEqual([23 ['a.txt', 1, 1, 1],24 ['b.txt', 1, 2, 2],25 ['c.txt', 1, 0, 0],26 ['d.txt', 0, 2, 2],27 ])28 // And finally the weirdo cases29 const acontent = await fs.read(path.join(dir, 'a.txt'))30 await fs.write(path.join(dir, 'a.txt'), 'Hi')31 await add({ fs, dir, gitdir, filepath: 'a.txt' })32 await fs.write(path.join(dir, 'a.txt'), acontent)33 matrix = await statusMatrix({ fs, dir, gitdir, filepaths: ['a.txt'] })34 expect(matrix).toEqual([['a.txt', 1, 1, 3]])35 await remove({ fs, dir, gitdir, filepath: 'a.txt' })36 matrix = await statusMatrix({ fs, dir, gitdir, filepaths: ['a.txt'] })37 expect(matrix).toEqual([['a.txt', 1, 1, 0]])38 await fs.write(path.join(dir, 'e.txt'), 'Hi')39 await add({ fs, dir, gitdir, filepath: 'e.txt' })40 await fs.rm(path.join(dir, 'e.txt'))41 matrix = await statusMatrix({ fs, dir, gitdir, filepaths: ['e.txt'] })42 expect(matrix).toEqual([['e.txt', 0, 0, 3]])43 })44 it('statusMatrix in an fresh git repo with no commits', async () => {45 // Setup46 const { fs, dir, gitdir } = await makeFixture('test-empty')47 await fs.write(path.join(dir, 'a.txt'), 'Hi')48 await fs.write(path.join(dir, 'b.txt'), 'Hi')49 await add({ fs, dir, gitdir, filepath: 'b.txt' })50 // Test51 const a = await statusMatrix({ fs, dir, gitdir, filepaths: ['a.txt'] })52 expect(a).toEqual([['a.txt', 0, 2, 0]])53 const b = await statusMatrix({ fs, dir, gitdir, filepaths: ['b.txt'] })54 expect(b).toEqual([['b.txt', 0, 2, 2]])55 })56 it('statusMatrix in an fresh git repo with no commits and .gitignore', async () => {57 // Setup58 const { fs, dir, gitdir } = await makeFixture('test-empty')59 await fs.write(path.join(dir, '.gitignore'), 'ignoreme.txt\n')60 await fs.write(path.join(dir, 'ignoreme.txt'), 'ignored')61 await add({ fs, dir, gitdir, filepath: '.' })62 // Test63 const a = await statusMatrix({ fs, dir, gitdir })64 expect(a).toEqual([['.gitignore', 0, 2, 2]])65 })66 it('does not return ignored files already in the index', async () => {67 // Setup68 const { fs, dir, gitdir } = await makeFixture('test-empty')69 await fs.write(path.join(dir, '.gitignore'), 'ignoreme.txt\n')70 await add({ fs, dir, gitdir, filepath: '.' })71 await fs.write(path.join(dir, 'ignoreme.txt'), 'ignored')72 // Test73 const a = await statusMatrix({ fs, dir, gitdir })74 expect(a).toEqual([['.gitignore', 0, 2, 2]])75 })76 it('returns ignored files already in the index if ignored:true', async () => {77 // Setup78 const { fs, dir, gitdir } = await makeFixture('test-empty')79 await fs.write(path.join(dir, '.gitignore'), 'ignoreme.txt\n')80 await add({ fs, dir, gitdir, filepath: '.' })81 await fs.write(path.join(dir, 'ignoreme.txt'), 'ignored')82 // Test83 const a = await statusMatrix({ fs, dir, gitdir, ignored: true })84 expect(a).toEqual([85 ['.gitignore', 0, 2, 2],86 ['ignoreme.txt', 0, 2, 0],87 ])88 })89 it('ignored:true works with multiple added files ', async () => {90 // Setup91 const { fs, dir, gitdir } = await makeFixture('test-empty')92 await fs.write(93 path.join(dir, '.gitignore'),94 'ignoreme.txt\nignoreme2.txt\n'95 )96 await add({ fs, dir, gitdir, filepath: '.' })97 await fs.write(path.join(dir, 'ignoreme.txt'), 'ignored')98 await fs.write(path.join(dir, 'ignoreme2.txt'), 'ignored')99 // Test100 const a = await statusMatrix({ fs, dir, gitdir, ignored: true })101 expect(a).toEqual([102 ['.gitignore', 0, 2, 2],103 ['ignoreme.txt', 0, 2, 0],104 ['ignoreme2.txt', 0, 2, 0],105 ])106 })107 describe('ignored:true works supports multiple filepaths', () => {108 let fs, dir, gitdir109 const ignoredFolder = 'ignoreThisFolder'110 const nonIgnoredFolder = 'nonIgnoredFolder'111 beforeAll(async () => {112 // Setup113 const output = await makeFixture('test-empty')114 fs = output.fs115 dir = output.dir116 gitdir = output.gitdir117 await fs.write(path.join(dir, '.gitignore'), `${ignoredFolder}/*\n`)118 await add({ fs, dir, gitdir, filepath: '.' })119 await fs.mkdir(path.join(dir, ignoredFolder))120 await fs.mkdir(path.join(dir, nonIgnoredFolder))121 await fs.write(122 path.join(dir, nonIgnoredFolder, 'notIgnored.txt'),123 'notIgnored'124 )125 await fs.write(path.join(dir, ignoredFolder, 'ignoreme.txt'), 'ignored')126 await fs.write(path.join(dir, 'notIgnored.txt'), 'notIgnored')127 })128 it('base case: no filepaths', async () => {129 const result = await statusMatrix({130 fs,131 dir,132 gitdir,133 ignored: true,134 })135 expect(result).toEqual([136 ['.gitignore', 0, 2, 2],137 [`${ignoredFolder}/ignoreme.txt`, 0, 2, 0],138 [`${nonIgnoredFolder}/notIgnored.txt`, 0, 2, 0],139 ['notIgnored.txt', 0, 2, 0],140 ])141 })142 it('filepaths on ignored folder should return empty', async () => {143 const result = await statusMatrix({144 fs,145 dir,146 gitdir,147 filepaths: [ignoredFolder],148 })149 expect(result).toEqual([])150 })151 it('shows nonignored file and folder', async () => {152 const result = await statusMatrix({153 fs,154 dir,155 gitdir,156 filepaths: [ignoredFolder, 'notIgnored.txt', nonIgnoredFolder],157 })158 expect(result).toEqual([159 [`${nonIgnoredFolder}/notIgnored.txt`, 0, 2, 0],160 ['notIgnored.txt', 0, 2, 0],161 ])162 })163 it('filepaths on ignored folder and non-ignored file should show all files with ignored:true ', async () => {164 const result = await statusMatrix({165 fs,166 dir,167 gitdir,168 filepaths: [ignoredFolder, 'notIgnored.txt', nonIgnoredFolder],169 ignored: true,170 })171 expect(result).toEqual([172 [`${ignoredFolder}/ignoreme.txt`, 0, 2, 0],173 [`${nonIgnoredFolder}/notIgnored.txt`, 0, 2, 0],174 ['notIgnored.txt', 0, 2, 0],175 ])176 })177 describe('all files, ignored:true, test order permutation', () => {178 it('file, ignored, notignored', async () => {179 const result = await statusMatrix({180 fs,181 dir,182 gitdir,183 filepaths: ['notIgnored.txt', ignoredFolder, nonIgnoredFolder],184 ignored: true,185 })186 expect(result).toEqual([187 [`${ignoredFolder}/ignoreme.txt`, 0, 2, 0],188 [`${nonIgnoredFolder}/notIgnored.txt`, 0, 2, 0],189 ['notIgnored.txt', 0, 2, 0],190 ])191 })192 it('ignored, notignored, file', async () => {193 const result = await statusMatrix({194 fs,195 dir,196 gitdir,197 filepaths: [ignoredFolder, nonIgnoredFolder, 'notIgnored.txt'],198 ignored: true,199 })200 expect(result).toEqual([201 [`${ignoredFolder}/ignoreme.txt`, 0, 2, 0],202 [`${nonIgnoredFolder}/notIgnored.txt`, 0, 2, 0],203 ['notIgnored.txt', 0, 2, 0],204 ])205 })206 it('notignored, ignored, file', async () => {207 const result = await statusMatrix({208 fs,209 dir,210 gitdir,211 filepaths: [nonIgnoredFolder, ignoredFolder, 'notIgnored.txt'],212 ignored: true,213 })214 expect(result).toEqual([215 [`${ignoredFolder}/ignoreme.txt`, 0, 2, 0],216 [`${nonIgnoredFolder}/notIgnored.txt`, 0, 2, 0],217 ['notIgnored.txt', 0, 2, 0],218 ])219 })220 })221 })222 it('ignored: true has no impact when file is already in index', async () => {223 // Setup224 const { fs, dir, gitdir } = await makeFixture('test-empty')225 await fs.write(path.join(dir, '.gitignore'), 'ignoreme.txt\n')226 await fs.write(path.join(dir, 'ignoreme.txt'), 'ignored')227 await add({ fs, dir, gitdir, filepath: '.', force: true })228 // Test229 const a = await statusMatrix({ fs, dir, gitdir, ignored: true })230 expect(a).toEqual([231 ['.gitignore', 0, 2, 2],232 ['ignoreme.txt', 0, 2, 2],233 ])234 // Test235 const b = await statusMatrix({ fs, dir, gitdir, ignored: false })236 expect(b).toEqual([237 ['.gitignore', 0, 2, 2],238 ['ignoreme.txt', 0, 2, 2],239 ])240 })241 it('statusMatrix with filepaths', async () => {242 // Setup243 const { fs, dir, gitdir } = await makeFixture('test-statusMatrix-filepath')244 // Test245 let matrix = await statusMatrix({ fs, dir, gitdir })246 expect(matrix).toEqual([247 ['a.txt', 1, 1, 1],248 ['b.txt', 1, 2, 1],249 ['c.txt', 1, 0, 1],250 ['d.txt', 0, 2, 0],251 ['g/g.txt', 0, 2, 0],252 ['h/h.txt', 0, 2, 0],253 ['i/.gitignore', 0, 2, 0],254 ['i/i.txt', 0, 2, 0],255 ])256 matrix = await statusMatrix({ fs, dir, gitdir, filepaths: ['i'] })257 expect(matrix).toEqual([258 ['i/.gitignore', 0, 2, 0],259 ['i/i.txt', 0, 2, 0],260 ])261 matrix = await statusMatrix({ fs, dir, gitdir, filepaths: [] })262 expect(matrix).toBeUndefined()263 matrix = await statusMatrix({ fs, dir, gitdir, filepaths: ['i', 'h'] })264 expect(matrix).toEqual([265 ['h/h.txt', 0, 2, 0],266 ['i/.gitignore', 0, 2, 0],267 ['i/i.txt', 0, 2, 0],268 ])269 })270 it('statusMatrix with filter', async () => {271 // Setup272 const { fs, dir, gitdir } = await makeFixture('test-statusMatrix-filepath')273 // Test274 let matrix = await statusMatrix({275 fs,276 dir,277 gitdir,278 filter: filepath => !filepath.includes('/') && filepath.endsWith('.txt'),279 })280 expect(matrix).toEqual([281 ['a.txt', 1, 1, 1],282 ['b.txt', 1, 2, 1],283 ['c.txt', 1, 0, 1],284 ['d.txt', 0, 2, 0],285 ])286 matrix = await statusMatrix({287 fs,288 dir,289 gitdir,290 filter: filepath => filepath.endsWith('.gitignore'),291 })292 expect(matrix).toEqual([['i/.gitignore', 0, 2, 0]])293 matrix = await statusMatrix({294 fs,295 dir,296 gitdir,297 filter: filepath => filepath.endsWith('.txt'),298 filepaths: ['i'],299 })300 expect(matrix).toEqual([['i/i.txt', 0, 2, 0]])301 })302 it('statusMatrix with removed folder and created file with same name', async () => {303 // Setup304 const { fs, dir, gitdir } = await makeFixture(305 'test-statusMatrix-tree-blob-collision'306 )307 // Test308 await fs.rmdir(path.join(dir, 'a'), { recursive: true })309 await fs.write(path.join(dir, 'a'), 'Hi')310 let matrix = await statusMatrix({311 fs,312 dir,313 gitdir,314 })315 expect(matrix).toEqual([316 ['a', 0, 2, 0],317 ['a/a.txt', 1, 0, 1],318 ['b', 1, 1, 1],319 ])320 await remove({ fs, dir, gitdir, filepath: 'a/a.txt' })321 await add({ fs, dir, gitdir, filepath: 'a' })322 matrix = await statusMatrix({323 fs,324 dir,325 gitdir,326 })327 expect(matrix).toEqual([328 ['a', 0, 2, 2],329 ['a/a.txt', 1, 0, 0],330 ['b', 1, 1, 1],331 ])332 })333 it('statusMatrix with removed file and created folder with same name', async () => {334 // Setup335 const { fs, dir, gitdir } = await makeFixture(336 'test-statusMatrix-blob-tree-collision'337 )338 // Test339 await fs.rm(path.join(dir, 'b'))340 await fs.mkdir(path.join(dir, 'b'))341 await fs.write(path.join(dir, 'b/b.txt'), 'Hi')342 let matrix = await statusMatrix({343 fs,344 dir,345 gitdir,346 })347 expect(matrix).toEqual([348 ['a/a.txt', 1, 1, 1],349 ['b', 1, 0, 1],350 ['b/b.txt', 0, 2, 0],351 ])352 await remove({ fs, dir, gitdir, filepath: 'b' })353 await add({ fs, dir, gitdir, filepath: 'b/b.txt' })354 matrix = await statusMatrix({355 fs,356 dir,357 gitdir,358 })359 expect(matrix).toEqual([360 ['a/a.txt', 1, 1, 1],361 ['b', 1, 0, 0],362 ['b/b.txt', 0, 2, 2],363 ])364 })...
globs.js
Source:globs.js
...180 };181 function isIgnoredByWatcher(file) {182 t.true(globs.classify(fixture(file), options).isIgnoredByWatcher, `${file} should be ignored`);183 }184 function notIgnored(file) {185 t.false(globs.classify(fixture(file), options).isIgnoredByWatcher, `${file} should not be ignored`);186 }187 notIgnored('foo-bar.js');188 notIgnored('foo.js');189 notIgnored('foo/blah.js');190 notIgnored('bar/foo.js');191 notIgnored('_foo-bar.js');192 notIgnored('foo/_foo-bar.js');193 notIgnored('fixtures/foo.js');194 notIgnored('helpers/foo.js');195 notIgnored('snapshots/foo.js.snap');196 isIgnoredByWatcher('snapshots/foo.js.snap.md');197 notIgnored('foo-bar.json');198 notIgnored('foo-bar.coffee');199 notIgnored('bar.js');200 notIgnored('bar/bar.js');201 isIgnoredByWatcher('node_modules/foo.js');202 t.end();203});204test('isIgnoredByWatcher with patterns', t => {205 const options = {206 ...globs.normalizeGlobs({207 files: ['**/foo*'],208 ignoredByWatcher: ['**/bar*'],209 extensions: ['js'],210 providers: []211 }),212 cwd: fixture()213 };214 t.true(globs.classify(fixture('node_modules/foo/foo.js'), options).isIgnoredByWatcher);...
WatchIgnorePlugin.js
Source:WatchIgnorePlugin.js
1/*2 MIT License http://www.opensource.org/licenses/mit-license.php3 Author Tobias Koppers @sokra4*/5"use strict";6class WatchIgnorePlugin {7 constructor(paths) {8 this.paths = paths;9 }10 apply(compiler) {11 compiler.plugin("after-environment", () => {12 compiler.watchFileSystem = new IgnoringWatchFileSystem(compiler.watchFileSystem, this.paths);13 });14 }15}16module.exports = WatchIgnorePlugin;17class IgnoringWatchFileSystem {18 constructor(wfs, paths) {19 this.wfs = wfs;20 this.paths = paths;21 }22 watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {23 const ignored = path => this.paths.some(p => p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0);24 const notIgnored = path => !ignored(path);25 const ignoredFiles = files.filter(ignored);26 const ignoredDirs = dirs.filter(ignored);27 this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps) => {28 if(err) return callback(err);29 ignoredFiles.forEach(path => {30 fileTimestamps[path] = 1;31 });32 ignoredDirs.forEach(path => {33 dirTimestamps[path] = 1;34 });35 callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps);36 }, callbackUndelayed);37 }...
Using AI Code Generation
1const availableExports = require('./availableExports');2const notIgnored = availableExports.notIgnored;3console.log(notIgnored());4const notIgnored = () => {5 return 'notIgnored';6};7module.exports = {8};
Using AI Code Generation
1var test = require('test');2var notIgnored = test.notIgnored;3var ignored = test.ignored;4var test2 = require('test2');5var notIgnored2 = test2.notIgnored;6var ignored2 = test2.ignored;7var test3 = require('test3');8var notIgnored3 = test3.notIgnored;9var ignored3 = test3.ignored;10var test = require('test');11var notIgnored = test.notIgnored;12var ignored = test.ignored;13var test2 = require('test2');14var notIgnored2 = test2.notIgnored;15var ignored2 = test2.ignored;16var test3 = require('test3');17var notIgnored3 = test3.notIgnored;18var ignored3 = test3.ignored;19var test = require('test');20var notIgnored = test.notIgnored;21var ignored = test.ignored;22var test2 = require('test2');23var notIgnored2 = test2.notIgnored;24var ignored2 = test2.ignored;25var test3 = require('test3');26var notIgnored3 = test3.notIgnored;27var ignored3 = test3.ignored;28var test = require('test');29var notIgnored = test.notIgnored;30var ignored = test.ignored;31var test2 = require('test2');32var notIgnored2 = test2.notIgnored;33var ignored2 = test2.ignored;34var test3 = require('test3');35var notIgnored3 = test3.notIgnored;36var ignored3 = test3.ignored;
Using AI Code Generation
1var availableModules = require('availableModules');2availableModules.notIgnored('test');3var ignoredModules = require('ignoredModules');4var notIgnored = function(moduleName) {5 return ignoredModules.indexOf(moduleName) === -1;6};7module.exports = {8};9module.exports = ['test', 'test2'];
Using AI Code Generation
1var availableFunctions = require('./availableFunctions.js');2var result = availableFunctions.notIgnored('test');3module.exports.notIgnored = function (input) {4 return input + ' was not ignored';5};6module.exports.ignored = function (input) {7 return input + ' was ignored';8};
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!!