How to use touchFile method in Mocha

Best JavaScript code snippet using mocha

watch.spec.js

Source:watch.spec.js Github

copy

Full Screen

...33 it('reruns test when watched test file is touched', function() {34 const testFile = path.join(tempDir, 'test.js');35 copyFixture(DEFAULT_FIXTURE, testFile);36 return runMochaWatchJSONAsync([testFile], tempDir, () => {37 touchFile(testFile);38 }).then(results => {39 expect(results, 'to have length', 2);40 });41 });42 it('reruns test when watched test file crashes', function() {43 const testFile = path.join(tempDir, 'test.js');44 copyFixture(DEFAULT_FIXTURE, testFile);45 replaceFileContents(testFile, 'done();', 'done((;');46 return runMochaWatchJSONAsync([testFile], tempDir, () => {47 replaceFileContents(testFile, 'done((;', 'done();');48 }).then(results => {49 expect(results, 'to have length', 1);50 });51 });52 describe('when in parallel mode', function() {53 it('reruns test when watched test file is touched', function() {54 const testFile = path.join(tempDir, 'test.js');55 copyFixture(DEFAULT_FIXTURE, testFile);56 return runMochaWatchJSONAsync(['--parallel', testFile], tempDir, () => {57 touchFile(testFile);58 }).then(results => {59 expect(results, 'to have length', 2);60 });61 });62 it('reruns test when watched test file is crashed', function() {63 const testFile = path.join(tempDir, 'test.js');64 copyFixture(DEFAULT_FIXTURE, testFile);65 replaceFileContents(testFile, 'done();', 'done((;');66 return runMochaWatchJSONAsync([testFile], tempDir, () => {67 replaceFileContents(testFile, 'done((;', 'done();');68 }).then(results => {69 expect(results, 'to have length', 1);70 });71 });72 });73 it('reruns test when file matching --watch-files changes', function() {74 const testFile = path.join(tempDir, 'test.js');75 copyFixture(DEFAULT_FIXTURE, testFile);76 const watchedFile = path.join(tempDir, 'dir/file.xyz');77 touchFile(watchedFile);78 return runMochaWatchJSONAsync(79 [testFile, '--watch-files', 'dir/*.xyz'],80 tempDir,81 () => {82 touchFile(watchedFile);83 }84 ).then(results => {85 expect(results.length, 'to equal', 2);86 });87 });88 it('reruns test when file matching --watch-files is added', function() {89 const testFile = path.join(tempDir, 'test.js');90 copyFixture(DEFAULT_FIXTURE, testFile);91 const watchedFile = path.join(tempDir, 'lib/file.xyz');92 return runMochaWatchJSONAsync(93 [testFile, '--watch-files', '**/*.xyz'],94 tempDir,95 () => {96 touchFile(watchedFile);97 }98 ).then(results => {99 expect(results, 'to have length', 2);100 });101 });102 it('reruns test when file matching --watch-files is removed', function() {103 const testFile = path.join(tempDir, 'test.js');104 copyFixture(DEFAULT_FIXTURE, testFile);105 const watchedFile = path.join(tempDir, 'lib/file.xyz');106 touchFile(watchedFile);107 return runMochaWatchJSONAsync(108 [testFile, '--watch-files', 'lib/**/*.xyz'],109 tempDir,110 () => {111 fs.removeSync(watchedFile);112 }113 ).then(results => {114 expect(results, 'to have length', 2);115 });116 });117 it('does not rerun test when file not matching --watch-files is changed', function() {118 const testFile = path.join(tempDir, 'test.js');119 copyFixture(DEFAULT_FIXTURE, testFile);120 const watchedFile = path.join(tempDir, 'dir/file.js');121 touchFile(watchedFile);122 return runMochaWatchJSONAsync(123 [testFile, '--watch-files', 'dir/*.xyz'],124 tempDir,125 () => {126 touchFile(watchedFile);127 }128 ).then(results => {129 expect(results.length, 'to equal', 1);130 });131 });132 it('picks up new test files when they are added', function() {133 const testFile = path.join(tempDir, 'test/a.js');134 copyFixture(DEFAULT_FIXTURE, testFile);135 return runMochaWatchJSONAsync(136 ['test/**/*.js', '--watch-files', 'test/**/*.js'],137 tempDir,138 () => {139 const addedTestFile = path.join(tempDir, 'test/b.js');140 copyFixture('passing', addedTestFile);141 }142 ).then(results => {143 expect(results, 'to have length', 2);144 expect(results[0].passes, 'to have length', 1);145 expect(results[1].passes, 'to have length', 3);146 });147 });148 it('reruns test when file matching --extension is changed', function() {149 const testFile = path.join(tempDir, 'test.js');150 copyFixture(DEFAULT_FIXTURE, testFile);151 const watchedFile = path.join(tempDir, 'file.xyz');152 touchFile(watchedFile);153 return runMochaWatchJSONAsync(154 [testFile, '--extension', 'xyz,js'],155 tempDir,156 () => {157 touchFile(watchedFile);158 }159 ).then(results => {160 expect(results, 'to have length', 2);161 });162 });163 it('reruns when "rs\\n" typed', function() {164 const testFile = path.join(tempDir, 'test.js');165 copyFixture(DEFAULT_FIXTURE, testFile);166 return runMochaWatchJSONAsync([testFile], tempDir, mochaProcess => {167 mochaProcess.stdin.write('rs\n');168 }).then(results => {169 expect(results, 'to have length', 2);170 });171 });172 it('reruns test when file starting with . and matching --extension is changed', function() {173 const testFile = path.join(tempDir, 'test.js');174 copyFixture(DEFAULT_FIXTURE, testFile);175 const watchedFile = path.join(tempDir, '.file.xyz');176 touchFile(watchedFile);177 return runMochaWatchJSONAsync(178 [testFile, '--extension', 'xyz,js'],179 tempDir,180 () => {181 touchFile(watchedFile);182 }183 ).then(results => {184 expect(results, 'to have length', 2);185 });186 });187 it('ignores files in "node_modules" and ".git" by default', function() {188 const testFile = path.join(tempDir, 'test.js');189 copyFixture(DEFAULT_FIXTURE, testFile);190 const nodeModulesFile = path.join(tempDir, 'node_modules', 'file.xyz');191 const gitFile = path.join(tempDir, '.git', 'file.xyz');192 touchFile(gitFile);193 touchFile(nodeModulesFile);194 return runMochaWatchJSONAsync(195 [testFile, '--extension', 'xyz,js'],196 tempDir,197 () => {198 touchFile(gitFile);199 touchFile(nodeModulesFile);200 }201 ).then(results => {202 expect(results, 'to have length', 1);203 });204 });205 it('ignores files matching --watch-ignore', function() {206 const testFile = path.join(tempDir, 'test.js');207 copyFixture(DEFAULT_FIXTURE, testFile);208 const watchedFile = path.join(tempDir, 'dir/file-to-ignore.xyz');209 touchFile(watchedFile);210 return runMochaWatchJSONAsync(211 [212 testFile,213 '--watch-files',214 'dir/*.xyz',215 '--watch-ignore',216 'dir/*ignore*'217 ],218 tempDir,219 () => {220 touchFile(watchedFile);221 }222 ).then(results => {223 expect(results.length, 'to equal', 1);224 });225 });226 it('reloads test files when they change', function() {227 const testFile = path.join(tempDir, 'test.js');228 copyFixture('options/watch/test-file-change', testFile);229 return runMochaWatchJSONAsync(230 [testFile, '--watch-files', '**/*.js'],231 tempDir,232 () => {233 replaceFileContents(234 testFile,235 'testShouldFail = true',236 'testShouldFail = false'237 );238 }239 ).then(results => {240 expect(results, 'to have length', 2);241 expect(results[0].passes, 'to have length', 0);242 expect(results[0].failures, 'to have length', 1);243 expect(results[1].passes, 'to have length', 1);244 expect(results[1].failures, 'to have length', 0);245 });246 });247 it('reloads test dependencies when they change', function() {248 const testFile = path.join(tempDir, 'test.js');249 copyFixture('options/watch/test-with-dependency', testFile);250 const dependency = path.join(tempDir, 'lib', 'dependency.js');251 copyFixture('options/watch/dependency', dependency);252 return runMochaWatchJSONAsync(253 [testFile, '--watch-files', 'lib/**/*.js'],254 tempDir,255 () => {256 replaceFileContents(257 dependency,258 'module.exports.testShouldFail = false',259 'module.exports.testShouldFail = true'260 );261 }262 ).then(results => {263 expect(results, 'to have length', 2);264 expect(results[0].passes, 'to have length', 1);265 expect(results[0].failures, 'to have length', 0);266 expect(results[1].passes, 'to have length', 0);267 expect(results[1].failures, 'to have length', 1);268 });269 });270 // Regression test for https://github.com/mochajs/mocha/issues/2027271 it('respects --fgrep on re-runs', async function() {272 const testFile = path.join(tempDir, 'test.js');273 copyFixture('options/grep', testFile);274 return expect(275 runMochaWatchJSONAsync([testFile, '--fgrep', 'match'], tempDir, () => {276 touchFile(testFile);277 }),278 'when fulfilled',279 'to satisfy',280 {281 length: 2,282 0: {tests: expect.it('to have length', 2)},283 1: {tests: expect.it('to have length', 2)}284 }285 );286 });287 describe('with required hooks', function() {288 /**289 * Helper for setting up hook tests290 *291 * @param {string} hookName name of hook to test292 * @return {function}293 */294 function setupHookTest(hookName) {295 return function() {296 const testFile = path.join(tempDir, 'test.js');297 const hookFile = path.join(tempDir, 'hook.js');298 copyFixture('__default__', testFile);299 copyFixture('options/watch/hook', hookFile);300 replaceFileContents(hookFile, '<hook>', hookName);301 return runMochaWatchJSONAsync(302 [testFile, '--require', hookFile],303 tempDir,304 () => {305 touchFile(testFile);306 }307 ).then(results => {308 expect(results.length, 'to equal', 2);309 expect(results[0].failures, 'to have length', 1);310 expect(results[1].failures, 'to have length', 1);311 });312 };313 }314 it('mochaHooks.beforeAll runs as expected', setupHookTest('beforeAll'));315 it('mochaHooks.beforeEach runs as expected', setupHookTest('beforeEach'));316 it('mochaHooks.afterAll runs as expected', setupHookTest('afterAll'));317 it('mochaHooks.afterEach runs as expected', setupHookTest('afterEach'));318 });319 it('should not leak event listeners', function() {320 this.timeout(20000);321 const testFile = path.join(tempDir, 'test.js');322 copyFixture(DEFAULT_FIXTURE, testFile);323 return expect(324 runMochaWatchAsync(325 [testFile],326 {cwd: tempDir, stdio: 'pipe'},327 async () => {328 // we want to cause _n + 1_ reruns, which should cause the warning329 // to occur if the listeners aren't properly destroyed330 const iterations = new Array(process.getMaxListeners() + 1);331 // eslint-disable-next-line no-unused-vars332 for await (const _ of iterations) {333 touchFile(testFile);334 await sleep(1000);335 }336 }337 ),338 'when fulfilled',339 'to satisfy',340 {341 output: expect.it('not to match', /MaxListenersExceededWarning/)342 }343 );344 });345 });...

Full Screen

Full Screen

test-watch.js

Source:test-watch.js Github

copy

Full Screen

...104};105Fiber(function () {106 console.log("Test Watcher");107 console.log("... one file");108 touchFile('/aa/b', 'kitten');109 go({110 files: { '/aa/b': true }111 });112 assert(!fires());113 touchFile('/aa/b', 'kitten');114 assert(!fires());115 touchFile('/aa/b', 'puppy');116 assert(fires());117 go();118 touchFile('/aa/b', 'puppy');119 assert(!fires());120 touchFile('/aa/b', 'kitten');121 assert(fires());122 go();123 remove('/aa/b');124 assert(fires());125 touchFile('/aa/b');126 go({127 files: { '/aa/b': true, '/aa/c': true }128 });129 assert(fires()); // look like /aa/c was removed130 go({131 files: { '/aa/b': true, '/aa/c': null }132 });133 assert(!fires()); // assert that /aa/c doesn't exist134 console.log("... directories");135 go({136 files: {'/aa/b': true },137 directories: [138 {absPath: '/aa',139 include: [/yes/, /maybe/, /aa/],140 exclude: [/not/, /never/],141 contents: []142 },143 {absPath: '/bb',144 include: [/.?/],145 contents: []146 }147 ]148 });149 assert(fires()); // because /bb doesn't exist150 touchDir('/bb');151 go();152 assert(!fires());153 touchFile('/aa/c');154 assert(!fires());155 touchFile('/aa/maybe-not');156 assert(!fires());157 touchFile('/aa/never-yes');158 assert(!fires());159 touchFile('/aa/never');160 assert(!fires());161 touchFile('/aa/yes-for-sure');162 assert(fires());163 go();164 touchFile('/aa/nope');165 assert(fires()); // because yes-for-sure isn't in 'contents'166 remove('/aa/yes-for-sure');167 go();168 assert(!fires());169 touchFile('/aa/maybe-this-time');170 assert(fires());171 go();172 assert(fires()); // maybe-this-time is still there173 go({174 files: {'/aa/b': true},175 directories: [176 {absPath: '/aa',177 include: [/yes/, /maybe/, /aa/],178 exclude: [/not/, /never/],179 contents: ['maybe-this-time']180 },181 {absPath: '/bb',182 include: [/.?/],183 contents: []184 }185 ]186 });187 go();188 assert(!fires()); // maybe-this-time is now in the expected file list189 touchFile('/aa/maybe-yes');190 assert(fires());191 remove('/aa/maybe-yes');192 remove('/aa/maybe-this-time');193 go();194 assert(fires()); // maybe-this-time is missing195 touchFile('/aa/maybe-this-time');196 touchDir('/aa/yes-i-said-yes-i-will-yes');197 go({198 directories: [199 {absPath: '/aa',200 include: [/yes/, /maybe/, /aa/],201 exclude: [/not/, /never/],202 contents: ['maybe-this-time']203 }204 ]205 });206 assert(fires()); // yes-i-said-yes-i-will-yes/ is missing207 go({208 directories: [209 {absPath: '/aa',210 include: [/yes/, /maybe/, /aa/],211 exclude: [/not/, /never/],212 contents: ['maybe-this-time', 'yes-i-said-yes-i-will-yes']213 }214 ]215 });216 assert(fires()); // yes-i-said-yes-i-will-yes is a dir, not a file217 go({218 directories: [219 {absPath: '/aa',220 include: [/yes/, /maybe/, /aa/],221 exclude: [/not/, /never/],222 contents: ['maybe-this-time', 'yes-i-said-yes-i-will-yes/']223 }224 ]225 });226 assert(!fires());227 // same directory, different filters228 go({229 directories: [230 // dirs231 {absPath: '/aa',232 include: [/\/$/],233 contents: ['yes-i-said-yes-i-will-yes/']234 },235 // files236 {absPath: '/aa',237 include: [/.?/],238 exclude: [/\/$/],239 contents: ['b', 'c', 'maybe-not', 'maybe-this-time', 'never',240 'never-yes', 'nope']241 }242 ]243 });244 assert(!fires());245 touchFile('/aa/bla');246 assert(fires());247 touchDir('/cc');248 go({249 directories: [250 {absPath: '/cc',251 names: ['abc-foo', 'def-bar'],252 exclude: [/foo/],253 contents: []254 }255 ]256 });257 assert(!fires());258 touchFile('/cc/abc-foo');259 // See that names overrides exclude.260 assert(fires());261 // nb: these are supposed to verify that the "wait a second and try again"262 // logic works, but I couldn't get them to fail even when I turned that logic263 // off.264 console.log("... rapid changes to file");265 touchFile('/aa/x');266 waitForTopOfSecond();267 go({268 files: {'/aa/x': true }});269 touchFile('/aa/x');270 assert(fires(2000));271 go({272 directories: [273 {absPath: '/aa',274 include: [/yes/, /maybe/, /aa/],275 exclude: [/not/, /never/]276 }277 ]278 });279 assert(!fires());280 waitForTopOfSecond();281 touchFile('/aa/wtf');282 delay(600);283 touchFile('/aa/yes-indeed');284 assert(fires(2000));285 remove('/aa');286 console.log("Watcher test passed");287 theWatcher.stop();...

Full Screen

Full Screen

35test-watch.js

Source:35test-watch.js Github

copy

Full Screen

...104};105Fiber(function () {106 console.log("Test Watcher");107 console.log("... one file");108 touchFile('/aa/b', 'kitten');109 go({110 files: { '/aa/b': true }111 });112 assert(!fires());113 touchFile('/aa/b', 'kitten');114 assert(!fires());115 touchFile('/aa/b', 'puppy');116 assert(fires());117 go();118 touchFile('/aa/b', 'puppy');119 assert(!fires());120 touchFile('/aa/b', 'kitten');121 assert(fires());122 go();123 remove('/aa/b');124 assert(fires());125 touchFile('/aa/b');126 go({127 files: { '/aa/b': true, '/aa/c': true }128 });129 assert(fires()); // look like /aa/c was removed130 go({131 files: { '/aa/b': true, '/aa/c': null }132 });133 assert(!fires()); // assert that /aa/c doesn't exist134 console.log("... directories");135 go({136 files: {'/aa/b': true },137 directories: [138 {absPath: '/aa',139 include: [/yes/, /maybe/, /aa/],140 exclude: [/not/, /never/],141 contents: []142 },143 {absPath: '/bb',144 include: [/.?/],145 contents: []146 }147 ]148 });149 assert(fires()); // because /bb doesn't exist150 touchDir('/bb');151 go();152 assert(!fires());153 touchFile('/aa/c');154 assert(!fires());155 touchFile('/aa/maybe-not');156 assert(!fires());157 touchFile('/aa/never-yes');158 assert(!fires());159 touchFile('/aa/never');160 assert(!fires());161 touchFile('/aa/yes-for-sure');162 assert(fires());163 go();164 touchFile('/aa/nope');165 assert(fires()); // because yes-for-sure isn't in 'contents'166 remove('/aa/yes-for-sure');167 go();168 assert(!fires());169 touchFile('/aa/maybe-this-time');170 assert(fires());171 go();172 assert(fires()); // maybe-this-time is still there173 go({174 files: {'/aa/b': true},175 directories: [176 {absPath: '/aa',177 include: [/yes/, /maybe/, /aa/],178 exclude: [/not/, /never/],179 contents: ['maybe-this-time']180 },181 {absPath: '/bb',182 include: [/.?/],183 contents: []184 }185 ]186 });187 go();188 assert(!fires()); // maybe-this-time is now in the expected file list189 touchFile('/aa/maybe-yes');190 assert(fires());191 remove('/aa/maybe-yes');192 remove('/aa/maybe-this-time');193 go();194 assert(fires()); // maybe-this-time is missing195 touchFile('/aa/maybe-this-time');196 touchDir('/aa/yes-i-said-yes-i-will-yes');197 go({198 directories: [199 {absPath: '/aa',200 include: [/yes/, /maybe/, /aa/],201 exclude: [/not/, /never/],202 contents: ['maybe-this-time']203 }204 ]205 });206 assert(fires()); // yes-i-said-yes-i-will-yes/ is missing207 go({208 directories: [209 {absPath: '/aa',210 include: [/yes/, /maybe/, /aa/],211 exclude: [/not/, /never/],212 contents: ['maybe-this-time', 'yes-i-said-yes-i-will-yes']213 }214 ]215 });216 assert(fires()); // yes-i-said-yes-i-will-yes is a dir, not a file217 go({218 directories: [219 {absPath: '/aa',220 include: [/yes/, /maybe/, /aa/],221 exclude: [/not/, /never/],222 contents: ['maybe-this-time', 'yes-i-said-yes-i-will-yes/']223 }224 ]225 });226 assert(!fires());227 // same directory, different filters228 go({229 directories: [230 // dirs231 {absPath: '/aa',232 include: [/\/$/],233 contents: ['yes-i-said-yes-i-will-yes/']234 },235 // files236 {absPath: '/aa',237 include: [/.?/],238 exclude: [/\/$/],239 contents: ['b', 'c', 'maybe-not', 'maybe-this-time', 'never',240 'never-yes', 'nope']241 }242 ]243 });244 assert(!fires());245 touchFile('/aa/bla');246 assert(fires());247 touchDir('/cc');248 go({249 directories: [250 {absPath: '/cc',251 names: ['abc-foo', 'def-bar'],252 exclude: [/foo/],253 contents: []254 }255 ]256 });257 assert(!fires());258 touchFile('/cc/abc-foo');259 // See that names overrides exclude.260 assert(fires());261 // nb: these are supposed to verify that the "wait a second and try again"262 // logic works, but I couldn't get them to fail even when I turned that logic263 // off.264 console.log("... rapid changes to file");265 touchFile('/aa/x');266 waitForTopOfSecond();267 go({268 files: {'/aa/x': true }});269 touchFile('/aa/x');270 assert(fires(2000));271 go({272 directories: [273 {absPath: '/aa',274 include: [/yes/, /maybe/, /aa/],275 exclude: [/not/, /never/]276 }277 ]278 });279 assert(!fires());280 waitForTopOfSecond();281 touchFile('/aa/wtf');282 delay(600);283 touchFile('/aa/yes-indeed');284 assert(fires(2000));285 remove('/aa');286 console.log("Watcher test passed");287 theWatcher.stop();...

Full Screen

Full Screen

test_watch.js

Source:test_watch.js Github

copy

Full Screen

...104};105Fiber(function () {106 console.log("Test Watcher");107 console.log("... one file");108 touchFile('/aa/b', 'kitten');109 go({110 files: { '/aa/b': true }111 });112 assert(!fires());113 touchFile('/aa/b', 'kitten');114 assert(!fires());115 touchFile('/aa/b', 'puppy');116 assert(fires());117 go();118 touchFile('/aa/b', 'puppy');119 assert(!fires());120 touchFile('/aa/b', 'kitten');121 assert(fires());122 go();123 remove('/aa/b');124 assert(fires());125 touchFile('/aa/b');126 go({127 files: { '/aa/b': true, '/aa/c': true }128 });129 assert(fires()); // look like /aa/c was removed130 go({131 files: { '/aa/b': true, '/aa/c': null }132 });133 assert(!fires()); // assert that /aa/c doesn't exist134 console.log("... directories");135 go({136 files: {'/aa/b': true },137 directories: [138 {absPath: '/aa',139 include: [/yes/, /maybe/, /aa/],140 exclude: [/not/, /never/],141 contents: []142 },143 {absPath: '/bb',144 include: [/.?/],145 contents: []146 }147 ]148 });149 assert(fires()); // because /bb doesn't exist150 touchDir('/bb');151 go();152 assert(!fires());153 touchFile('/aa/c');154 assert(!fires());155 touchFile('/aa/maybe-not');156 assert(!fires());157 touchFile('/aa/never-yes');158 assert(!fires());159 touchFile('/aa/never');160 assert(!fires());161 touchFile('/aa/yes-for-sure');162 assert(fires());163 go();164 touchFile('/aa/nope');165 assert(fires()); // because yes-for-sure isn't in 'contents'166 remove('/aa/yes-for-sure');167 go();168 assert(!fires());169 touchFile('/aa/maybe-this-time');170 assert(fires());171 go();172 assert(fires()); // maybe-this-time is still there173 go({174 files: {'/aa/b': true},175 directories: [176 {absPath: '/aa',177 include: [/yes/, /maybe/, /aa/],178 exclude: [/not/, /never/],179 contents: ['maybe-this-time']180 },181 {absPath: '/bb',182 include: [/.?/],183 contents: []184 }185 ]186 });187 go();188 assert(!fires()); // maybe-this-time is now in the expected file list189 touchFile('/aa/maybe-yes');190 assert(fires());191 remove('/aa/maybe-yes');192 remove('/aa/maybe-this-time');193 go();194 assert(fires()); // maybe-this-time is missing195 touchFile('/aa/maybe-this-time');196 touchDir('/aa/yes-i-said-yes-i-will-yes');197 go({198 directories: [199 {absPath: '/aa',200 include: [/yes/, /maybe/, /aa/],201 exclude: [/not/, /never/],202 contents: ['maybe-this-time']203 }204 ]205 });206 assert(fires()); // yes-i-said-yes-i-will-yes/ is missing207 go({208 directories: [209 {absPath: '/aa',210 include: [/yes/, /maybe/, /aa/],211 exclude: [/not/, /never/],212 contents: ['maybe-this-time', 'yes-i-said-yes-i-will-yes']213 }214 ]215 });216 assert(fires()); // yes-i-said-yes-i-will-yes is a dir, not a file217 go({218 directories: [219 {absPath: '/aa',220 include: [/yes/, /maybe/, /aa/],221 exclude: [/not/, /never/],222 contents: ['maybe-this-time', 'yes-i-said-yes-i-will-yes/']223 }224 ]225 });226 assert(!fires());227 // same directory, different filters228 go({229 directories: [230 // dirs231 {absPath: '/aa',232 include: [/\/$/],233 contents: ['yes-i-said-yes-i-will-yes/']234 },235 // files236 {absPath: '/aa',237 include: [/.?/],238 exclude: [/\/$/],239 contents: ['b', 'c', 'maybe-not', 'maybe-this-time', 'never',240 'never-yes', 'nope']241 }242 ]243 });244 assert(!fires());245 touchFile('/aa/bla');246 assert(fires());247 // nb: these are supposed to verify that the "wait a second and try again"248 // logic works, but I couldn't get them to fail even when I turned that logic249 // off.250 console.log("... rapid changes to file");251 touchFile('/aa/x');252 waitForTopOfSecond();253 go({254 files: {'/aa/x': true }});255 touchFile('/aa/x');256 assert(fires(2000));257 go({258 directories: [259 {absPath: '/aa',260 include: [/yes/, /maybe/, /aa/],261 exclude: [/not/, /never/]262 }263 ]264 });265 assert(!fires());266 waitForTopOfSecond();267 touchFile('/aa/wtf');268 delay(600);269 touchFile('/aa/yes-indeed');270 assert(fires(2000));271 remove('/aa');272 console.log("Watcher test passed");273 theWatcher.stop();...

Full Screen

Full Screen

server_utils.js

Source:server_utils.js Github

copy

Full Screen

1`use strict`;2const fsp = require('fs').promises;3async function touchFile(filename) {4 try {5 // update timestamp, do not overwrite existing data6 let time = new Date();7 await fsp.utimesSync(filename, time, time);8 return true;9 } catch (ignored) {10 // if the above failed we create an empty file11 try {12 await fsp.writeFile(filename, "");13 return true;14 } catch (write_failed) {15 console.log("could not touch file <" + filename + ">: " + write_failed);16 return false;17 }18 }19}20/*21(async () => {22 console.log("init");23 console.log("a", await touchFile("./tmp1/a"));24 console.log("b", await touchFile("./tmp1/b"));25 console.log("c", await touchFile("./tmp1/c"));26 console.log("done");27})();28*/29module.exports = exports = {30 touchFile: touchFile...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require('mocha');2var mocha = new Mocha();3mocha.addFile('test1.js');4mocha.run(function(failures){5 process.on('exit', function () {6 });7});8var assert = require('assert');9describe('Array', function () {10 describe('#indexOf()', function () {11 it('should return -1 when the value is not present', function () {12 assert.equal(-1, [1,2,3].indexOf(5));13 assert.equal(-1, [1,2,3].indexOf(0));14 });15 });16});17var Mocha = require('mocha');18var mocha = new Mocha();19mocha.addFile('test1.js');20mocha.run(function(failures){21 process.on('exit', function () {22 });23});24var assert = require('assert');25describe('Array', function () {26 describe('#indexOf()', function () {27 it('should return -1 when the value is not present', function () {28 assert.equal(-1, [1,2,3].indexOf(5));29 assert.equal(-1, [1,2,3].indexOf(0));30 });31 });32});33var Mocha = require('mocha');34var mocha = new Mocha();35mocha.addFile('test1.js');36mocha.run(function(failures){37 process.on('exit', function () {38 });39});40var assert = require('assert');41describe('Array', function () {42 describe('#indexOf()', function () {43 it('should return -1 when the value is not present', function () {44 assert.equal(-1, [1,2,3].indexOf(5));45 assert.equal(-1, [1,2,3].indexOf(0));46 });47 });48});

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var touch = require('touch');3describe('File', function() {4 describe('#touch()', function() {5 it('should update the modification and access times', function(done) {6 fs.stat('file.txt', function(err, before) {7 touch('file.txt', function(err) {8 fs.stat('file.txt', function(err, after) {9 before.mtime.getTime().should.equal(after.mtime.getTime());10 before.atime.getTime().should.equal(after.atime.getTime());11 done();12 });13 });14 });15 })16 })17})

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var Mocha = require('mocha');3var mocha = new Mocha();4mocha.addFile('./test/test.js');5mocha.run(function(failures){6 process.on('exit', function () {7 });8});9var assert = require('assert');10describe('Array', function() {11 describe('#indexOf()', function() {12 it('should return -1 when the value is not present', function() {13 assert.equal(-1, [1,2,3].indexOf(4));14 });15 });16});

Full Screen

Using AI Code Generation

copy

Full Screen

1const chai = require('chai');2const expect = chai.expect;3const Mocha = require('mocha');4describe('Test Suite', function() {5 it('Test Case', function() {6 const mocha = new Mocha();7 mocha.touchFile();8 });9});10const chai = require('chai');11const expect = chai.expect;12const Mocha = require('mocha');13describe('Test Suite 1', function() {14 describe('Test Suite 2', function() {15 it('Test Case', function() {16 const mocha = new Mocha();17 expect(mocha.suite.suites).to.have.lengthOf(1);18 });19 });20});21const chai = require('chai');22const expect = chai.expect;23const Mocha = require('mocha');24describe('Test Suite 1', function() {25 it('Test Case 1', function() {26 const mocha = new Mocha();27 expect(mocha.suite.tests).to.have.lengthOf(1);28 });29 it('Test Case 2', function() {30 const mocha = new Mocha();31 expect(mocha.suite.tests).to.have.lengthOf(2);32 });33});34const chai = require('chai');35const expect = chai.expect;36const Mocha = require('mocha');37describe('Test Suite', function() {38 it('Test Case', function() {39 const mocha = new Mocha();40 expect(mocha.suite.title).to.equal('Test Suite');41 });42});43const chai = require('chai');44const expect = chai.expect;

Full Screen

Using AI Code Generation

copy

Full Screen

1var touch = require('touch');2var fs = require('fs');3touch('./test.txt');4if (fs.existsSync('./test.txt')) {5 console.log('file exists');6} else {7 console.log('file does not exist');8}9fs.unlinkSync('./test.txt');10if (fs.existsSync('./test.txt')) {11 console.log('file exists');12} else {13 console.log('file does not exist');14}

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require('mocha');2var mocha = new Mocha();3mocha.addFile('./test.js');4mocha.run(function(failures){5 process.on('exit', function () {6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var touch = require('touch');2touchFile('test.js');3var watch = require('watch');4watch.watchTree('./', function (f, curr, prev) {5 if (typeof f == "object" && prev === null && curr === null) {6 } else if (prev === null) {7 } else if (curr.nlink === 0) {8 } else {9 }10});11var watch = require('watch');12watch.unwatchTree('./');13var watch = require('watch');14watch.unwatchFile('test.js');15var fs = require('fs');16var stream = fs.createWriteStream('test.js');17var fs = require('fs');18var stream = fs.createReadStream('test.js');19var fs = require('fs');20var data = fs.readFileSync('test.js');21var fs = require('fs');22fs.readFile('test.js', function (err, data) {23 if (err) throw err;24 console.log(data.toString());25});26var fs = require('fs');27fs.read(fd, buffer, offset, length, position, callback

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mocha automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful