How to use readdirSync method in Jest

Best JavaScript code snippet using jest

load-plugins.spec.js

Source:load-plugins.spec.js Github

copy

Full Screen

1/* global describe:true, it:true */2// Test setup:3import { expect, NOOP, sinon } from '../test-setup';4// Dependencies:5import fs from 'fs';6import module from 'module';7import path from 'path';8import * as tractorLogger from 'tractor-logger';9import { TractorError } from 'tractor-error-handler';10// Under test:11import { loadPlugins } from './load-plugins';12describe('tractor-plugin-loader:', () => {13 describe('load-plugins:', () => {14 it('should do nothing if there is not any installed plugins', () => {15 let nodeModules = [];16 sinon.stub(fs, 'readdirSync').returns(nodeModules);17 sinon.stub(tractorLogger, 'info');18 let plugins = loadPlugins();19 expect(plugins.length).to.equal(0);20 fs.readdirSync.restore();21 tractorLogger.info.restore();22 });23 it('should create a plugin for each installed plugin', () => {24 let nodeModules = ['tractor-plugin-test'];25 let pluginModule = {};26 sinon.stub(fs, 'readdirSync').returns(nodeModules);27 sinon.stub(module, '_load').returns(pluginModule);28 sinon.stub(tractorLogger, 'info');29 let plugins = loadPlugins();30 expect(plugins.length).to.equal(1);31 expect(pluginModule.fullName).to.equal('tractor-plugin-test');32 expect(pluginModule.name).to.equal('test');33 fs.readdirSync.restore();34 module._load.restore();35 tractorLogger.info.restore();36 });37 it('should create a plugin for an ES2015 module', () => {38 let nodeModules = ['tractor-plugin-test'];39 let pluginModule = {40 default: {}41 };42 sinon.stub(fs, 'readdirSync').returns(nodeModules);43 sinon.stub(module, '_load').returns(pluginModule);44 sinon.stub(tractorLogger, 'info');45 let plugins = loadPlugins();46 expect(plugins.length).to.equal(1);47 fs.readdirSync.restore();48 module._load.restore();49 tractorLogger.info.restore();50 });51 it('should throw if the plugin cannot be loaded', () => {52 let nodeModules = ['tractor-plugin-test'];53 sinon.stub(fs, 'readdirSync').returns(nodeModules);54 sinon.stub(module, '_load').throws(new Error());55 sinon.stub(tractorLogger, 'info');56 expect(() => {57 loadPlugins();58 }).to.throw(TractorError, `could not require 'tractor-plugin-test'`);59 fs.readdirSync.restore();60 module._load.restore();61 tractorLogger.info.restore();62 });63 it('should decorate the `description` with display values', () => {64 let nodeModules = ['tractor-plugin-test-plugin'];65 let pluginModule = {};66 sinon.stub(fs, 'readdirSync').returns(nodeModules);67 sinon.stub(module, '_load').returns(pluginModule);68 sinon.stub(tractorLogger, 'info');69 let plugins = loadPlugins();70 let [test] = plugins;71 expect(test.description.name).to.equal('Test Plugin');72 expect(test.description.variableName).to.equal('testPlugin');73 expect(test.description.url).to.equal('test-plugin');74 fs.readdirSync.restore();75 module._load.restore();76 tractorLogger.info.restore();77 });78 it('should not overwrite an existing `description`', () => {79 let nodeModules = ['tractor-plugin-test-plugin'];80 let pluginModule = {81 description: {}82 };83 sinon.stub(fs, 'readdirSync').returns(nodeModules);84 sinon.stub(module, '_load').returns(pluginModule);85 sinon.stub(tractorLogger, 'info');86 let plugins = loadPlugins();87 let [test] = plugins;88 expect(test.description).to.equal(pluginModule.description);89 fs.readdirSync.restore();90 module._load.restore();91 tractorLogger.info.restore();92 });93 it('should decorate the `description` with the version', () => {94 let nodeModules = ['tractor-plugin-test-plugin'];95 let pluginModule = {};96 let pluginPackage = {97 version: '0.1.0'98 };99 sinon.stub(process, 'cwd').returns('');100 sinon.stub(fs, 'readdirSync').returns(nodeModules);101 sinon.stub(module, '_load')102 .withArgs('node_modules/tractor-plugin-test-plugin').returns(pluginModule)103 .withArgs('node_modules/tractor-plugin-test-plugin/package.json').returns(pluginPackage);104 sinon.stub(tractorLogger, 'info');105 let plugins = loadPlugins();106 let [test] = plugins;107 expect(test.description.version).to.equal('0.1.0');108 process.cwd.restore();109 fs.readdirSync.restore();110 module._load.restore();111 tractorLogger.info.restore();112 });113 it('should have a default `create` function that is a noop', () => {114 let nodeModules = ['tractor-plugin-test'];115 let pluginModule = {};116 sinon.stub(fs, 'readdirSync').returns(nodeModules);117 sinon.stub(module, '_load').returns(pluginModule);118 sinon.stub(tractorLogger, 'info');119 let plugins = loadPlugins();120 let [test] = plugins;121 expect(() => {122 test.create();123 }).to.not.throw();124 fs.readdirSync.restore();125 module._load.restore();126 tractorLogger.info.restore();127 });128 it('should not overwrite an existing `create` function', () => {129 let nodeModules = ['tractor-plugin-test'];130 let pluginModule = {131 create: NOOP132 };133 sinon.stub(fs, 'readdirSync').returns(nodeModules);134 sinon.stub(module, '_load').returns(pluginModule);135 sinon.stub(pluginModule, 'create');136 sinon.stub(tractorLogger, 'info');137 let plugins = loadPlugins();138 let [test] = plugins;139 test.create();140 expect(pluginModule.create).to.have.been.called();141 fs.readdirSync.restore();142 module._load.restore();143 tractorLogger.info.restore();144 });145 it('should have a default `init` function that is a noop', () => {146 let nodeModules = ['tractor-plugin-test'];147 let pluginModule = {};148 sinon.stub(fs, 'readdirSync').returns(nodeModules);149 sinon.stub(module, '_load').returns(pluginModule);150 sinon.stub(tractorLogger, 'info');151 let plugins = loadPlugins();152 let [test] = plugins;153 expect(() => {154 test.init();155 }).to.not.throw();156 fs.readdirSync.restore();157 module._load.restore();158 tractorLogger.info.restore();159 });160 it('should not overwrite an existing `init` function', () => {161 let nodeModules = ['tractor-plugin-test'];162 let pluginModule = {163 init: NOOP164 };165 sinon.stub(fs, 'readdirSync').returns(nodeModules);166 sinon.stub(module, '_load').returns(pluginModule);167 sinon.stub(pluginModule, 'init');168 sinon.stub(tractorLogger, 'info');169 let plugins = loadPlugins();170 let [test] = plugins;171 test.init();172 expect(pluginModule.init).to.have.been.called();173 fs.readdirSync.restore();174 module._load.restore();175 tractorLogger.info.restore();176 });177 it('should have a default `plugin` function that is a noop', () => {178 let nodeModules = ['tractor-plugin-test'];179 let pluginModule = {};180 sinon.stub(fs, 'readdirSync').returns(nodeModules);181 sinon.stub(module, '_load').returns(pluginModule);182 sinon.stub(tractorLogger, 'info');183 let plugins = loadPlugins();184 let [test] = plugins;185 expect(() => {186 test.plugin();187 }).to.not.throw();188 fs.readdirSync.restore();189 module._load.restore();190 tractorLogger.info.restore();191 });192 it('should not overwrite an existing `plugin` function', () => {193 let nodeModules = ['tractor-plugin-test'];194 let pluginModule = {195 plugin: NOOP196 };197 sinon.stub(fs, 'readdirSync').returns(nodeModules);198 sinon.stub(module, '_load').returns(pluginModule);199 sinon.stub(pluginModule, 'plugin');200 sinon.stub(tractorLogger, 'info');201 let plugins = loadPlugins();202 let [test] = plugins;203 test.plugin();204 expect(pluginModule.plugin).to.have.been.called();205 fs.readdirSync.restore();206 module._load.restore();207 tractorLogger.info.restore();208 });209 it('should have a default `run` function that is a noop', () => {210 let nodeModules = ['tractor-plugin-test'];211 let pluginModule = {};212 sinon.stub(fs, 'readdirSync').returns(nodeModules);213 sinon.stub(module, '_load').returns(pluginModule);214 sinon.stub(tractorLogger, 'info');215 let plugins = loadPlugins();216 let [test] = plugins;217 expect(() => {218 test.run();219 }).to.not.throw();220 fs.readdirSync.restore();221 module._load.restore();222 tractorLogger.info.restore();223 });224 it('should not overwrite an existing `run` function', () => {225 let nodeModules = ['tractor-plugin-test'];226 let pluginModule = {227 run: NOOP228 };229 sinon.stub(fs, 'readdirSync').returns(nodeModules);230 sinon.stub(module, '_load').returns(pluginModule);231 sinon.stub(pluginModule, 'run');232 sinon.stub(tractorLogger, 'info');233 let plugins = loadPlugins();234 let [test] = plugins;235 test.run();236 expect(pluginModule.run).to.have.been.called();237 fs.readdirSync.restore();238 module._load.restore();239 tractorLogger.info.restore();240 });241 it('should have a default `serve` function that is a noop', () => {242 let nodeModules = ['tractor-plugin-test'];243 let pluginModule = {};244 sinon.stub(fs, 'readdirSync').returns(nodeModules);245 sinon.stub(module, '_load').returns(pluginModule);246 sinon.stub(tractorLogger, 'info');247 let plugins = loadPlugins();248 let [test] = plugins;249 expect(() => {250 test.serve();251 }).to.not.throw();252 fs.readdirSync.restore();253 module._load.restore();254 tractorLogger.info.restore();255 });256 it('should not overwrite an existing `serve` function', () => {257 let nodeModules = ['tractor-plugin-test'];258 let pluginModule = {259 serve: NOOP260 };261 sinon.stub(fs, 'readdirSync').returns(nodeModules);262 sinon.stub(module, '_load').returns(pluginModule);263 sinon.stub(pluginModule, 'serve');264 sinon.stub(tractorLogger, 'info');265 let plugins = loadPlugins();266 let [test] = plugins;267 test.serve();268 expect(pluginModule.serve).to.have.been.called();269 fs.readdirSync.restore();270 module._load.restore();271 tractorLogger.info.restore();272 });273 it('should have a default `upgrade` function that is a noop', () => {274 let nodeModules = ['tractor-plugin-test'];275 let pluginModule = {};276 sinon.stub(fs, 'readdirSync').returns(nodeModules);277 sinon.stub(module, '_load').returns(pluginModule);278 sinon.stub(tractorLogger, 'info');279 let plugins = loadPlugins();280 let [test] = plugins;281 expect(() => {282 test.upgrade();283 }).to.not.throw();284 fs.readdirSync.restore();285 module._load.restore();286 tractorLogger.info.restore();287 });288 it('should not overwrite an existing `upgrade` function', () => {289 let nodeModules = ['tractor-plugin-test'];290 let pluginModule = {291 upgrade: NOOP292 };293 sinon.stub(fs, 'readdirSync').returns(nodeModules);294 sinon.stub(module, '_load').returns(pluginModule);295 sinon.stub(pluginModule, 'upgrade');296 sinon.stub(tractorLogger, 'info');297 let plugins = loadPlugins();298 let [test] = plugins;299 test.upgrade();300 expect(pluginModule.upgrade).to.have.been.called();301 fs.readdirSync.restore();302 module._load.restore();303 tractorLogger.info.restore();304 });305 it('should try to load the UI bundle and set the `hasUI` flag to true if it works', () => {306 let nodeModules = ['tractor-plugin-test'];307 let pluginModule = {};308 sinon.stub(fs, 'accessSync').returns(true);309 sinon.stub(fs, 'readdirSync').returns(nodeModules);310 sinon.stub(module, '_load').returns(pluginModule);311 sinon.stub(process, 'cwd').returns('.');312 sinon.stub(tractorLogger, 'info');313 let plugins = loadPlugins();314 let [test] = plugins;315 expect(test.script).to.equal(path.join('node_modules', 'tractor-plugin-test', 'dist', 'client', 'bundle.js'));316 expect(test.description.hasUI).to.equal(true);317 fs.accessSync.restore();318 fs.readdirSync.restore();319 module._load.restore();320 process.cwd.restore();321 tractorLogger.info.restore();322 });323 it('should try to load the UI bundle and set the `hasUI` flag to false if it fails', () => {324 let nodeModules = ['tractor-plugin-test'];325 let pluginModule = {};326 sinon.stub(fs, 'accessSync').throws(new Error());327 sinon.stub(fs, 'readdirSync').returns(nodeModules);328 sinon.stub(module, '_load').returns(pluginModule);329 sinon.stub(process, 'cwd').returns('.');330 sinon.stub(tractorLogger, 'info');331 let plugins = loadPlugins();332 let [test] = plugins;333 expect(test.description.hasUI).to.equal(false);334 fs.accessSync.restore();335 fs.readdirSync.restore();336 module._load.restore();337 process.cwd.restore();338 tractorLogger.info.restore();339 });340 });...

Full Screen

Full Screen

sync.spec.js

Source:sync.spec.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3const assert = require("assert");4const path = require("path");5const sinon = require("sinon");6const fs_macchiato_1 = require("../../../fs.macchiato");7const constants_1 = require("../constants");8const settings_1 = require("../settings");9const provider = require("./sync");10const ROOT_PATH = 'root';11const FIRST_FILE_PATH = 'first.txt';12const SECOND_FILE_PATH = 'second.txt';13const FIRST_ENTRY_PATH = path.join(ROOT_PATH, FIRST_FILE_PATH);14const SECOND_ENTRY_PATH = path.join(ROOT_PATH, SECOND_FILE_PATH);15describe('Providers → Sync', () => {16 describe('.read', () => {17 it('should call correct method based on Node.js version', () => {18 const readdirSync = sinon.stub().returns([]);19 const settings = new settings_1.default({20 fs: { readdirSync: readdirSync }21 });22 const actual = provider.read(ROOT_PATH, settings);23 assert.deepStrictEqual(actual, []);24 if (constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {25 assert.deepStrictEqual(readdirSync.args, [[ROOT_PATH, { withFileTypes: true }]]);26 }27 else {28 assert.deepStrictEqual(readdirSync.args, [[ROOT_PATH]]);29 }30 });31 it('should always use `readdir` method when the `stats` option is enabled', () => {32 const readdirSync = sinon.stub().returns([]);33 const settings = new settings_1.default({34 fs: { readdirSync: readdirSync },35 stats: true36 });37 provider.read(ROOT_PATH, settings);38 assert.deepStrictEqual(readdirSync.args, [[ROOT_PATH]]);39 });40 });41 describe('.readdirWithFileTypes', () => {42 it('should return entries', () => {43 const dirent = new fs_macchiato_1.Dirent({ name: FIRST_FILE_PATH });44 const readdirSync = sinon.stub().returns([dirent]);45 const settings = new settings_1.default({46 fs: { readdirSync: readdirSync }47 });48 const expected = [49 {50 dirent,51 name: FIRST_FILE_PATH,52 path: FIRST_ENTRY_PATH53 }54 ];55 const actual = provider.readdirWithFileTypes(ROOT_PATH, settings);56 assert.deepStrictEqual(readdirSync.args, [[ROOT_PATH, { withFileTypes: true }]]);57 assert.deepStrictEqual(actual, expected);58 });59 it('should call fs.stat for symbolic link when the "followSymbolicLink" option is enabled', () => {60 const firstDirent = new fs_macchiato_1.Dirent({ name: FIRST_FILE_PATH });61 const secondDirent = new fs_macchiato_1.Dirent({ name: SECOND_FILE_PATH, isSymbolicLink: true });62 const stats = new fs_macchiato_1.Stats();63 const readdirSync = sinon.stub().returns([firstDirent, secondDirent]);64 const statSync = sinon.stub().returns(stats);65 const settings = new settings_1.default({66 followSymbolicLinks: true,67 fs: {68 readdirSync: readdirSync,69 statSync: statSync70 }71 });72 const actual = provider.readdirWithFileTypes(ROOT_PATH, settings);73 assert.strictEqual(actual.length, 2);74 assert.deepStrictEqual(statSync.args, [[SECOND_ENTRY_PATH]]);75 assert.ok(!actual[1].dirent.isSymbolicLink());76 });77 it('should return lstat for broken symbolic link when the "throwErrorOnBrokenSymbolicLink" option is disabled', () => {78 const dirent = new fs_macchiato_1.Dirent({ name: FIRST_FILE_PATH, isSymbolicLink: true });79 const readdirSync = sinon.stub().returns([dirent]);80 const statSync = () => {81 throw new Error('error');82 };83 const settings = new settings_1.default({84 followSymbolicLinks: true,85 throwErrorOnBrokenSymbolicLink: false,86 fs: {87 readdirSync: readdirSync,88 statSync: statSync89 }90 });91 const actual = provider.readdirWithFileTypes(ROOT_PATH, settings);92 assert.strictEqual(actual.length, 1);93 });94 it('should throw an error fro broken symbolic link when the "throwErrorOnBrokenSymbolicLink" option is enabled', () => {95 const dirent = new fs_macchiato_1.Dirent({ name: FIRST_FILE_PATH, isSymbolicLink: true });96 const readdirSync = sinon.stub().returns([dirent]);97 const statSync = () => {98 throw new Error('error');99 };100 const settings = new settings_1.default({101 followSymbolicLinks: true,102 throwErrorOnBrokenSymbolicLink: true,103 fs: {104 readdirSync: readdirSync,105 statSync: statSync106 }107 });108 const expectedErrorMessageRe = /Error: error/;109 assert.throws(() => provider.readdirWithFileTypes(ROOT_PATH, settings), expectedErrorMessageRe);110 });111 });112 describe('.readdir', () => {113 it('should return entries', () => {114 const stats = new fs_macchiato_1.Stats();115 const readdirSync = sinon.stub().returns([FIRST_FILE_PATH]);116 const lstatSync = sinon.stub().returns(stats);117 const settings = new settings_1.default({118 fs: {119 readdirSync: readdirSync,120 lstatSync: lstatSync121 }122 });123 const actual = provider.readdir(ROOT_PATH, settings);124 assert.deepStrictEqual(readdirSync.args, [[ROOT_PATH]]);125 assert.strictEqual(actual[0].name, FIRST_FILE_PATH);126 assert.strictEqual(actual[0].path, FIRST_ENTRY_PATH);127 assert.strictEqual(actual[0].dirent.name, FIRST_FILE_PATH);128 });129 it('should return entries with `stats` property', () => {130 const stats = new fs_macchiato_1.Stats();131 const readdirSync = sinon.stub().returns([FIRST_FILE_PATH]);132 const lstatSync = sinon.stub().returns(stats);133 const settings = new settings_1.default({134 fs: {135 readdirSync: readdirSync,136 lstatSync: lstatSync137 },138 stats: true139 });140 const actual = provider.readdir(ROOT_PATH, settings);141 assert.deepStrictEqual(actual[0].stats, stats);142 });143 });...

Full Screen

Full Screen

cwd.js

Source:cwd.js Github

copy

Full Screen

...21 glob.files = [];22 });23 });24 it('should use the given cwd:', function () {25 glob.readdirSync('**/d').should.containDeep([ 'a/b/c/d', 'a/c/d' ]);26 glob.readdirSync('**/d', { cwd: 'a' }).should.containDeep([ 'b/c/d', 'c/d' ]);27 glob.readdirSync('**/d', { cwd: 'a/b' }).should.containDeep([ 'c/d' ]);28 glob.readdirSync('**/d', { cwd: path.resolve('a') }).should.containDeep([ 'b/c/d', 'c/d' ]);29 glob.readdirSync('**/d', { cwd: path.resolve('a/b') }).should.containDeep([ 'c/d' ]);30 glob.readdirSync('**/d', { cwd: path.resolve('a/b/') }).should.containDeep([ 'c/d' ]);31 glob.readdirSync('**/d', { cwd: path.resolve('a/b/') }).should.containDeep([ 'c/d' ]);32 glob.readdirSync('**/d', { cwd: process.cwd() }).should.containDeep([ 'a/b/c/d', 'a/c/d' ]);33 glob.readdirSync('a/**/d', { cwd: process.cwd() }).should.containDeep([ 'a/b/c/d', 'a/c/d' ]);34 glob.readdirSync('assets/**/m*.css').should.containDeep(['assets/css/main.css']);35 glob.readdirSync('b/*.js').should.containDeep(['b/a.js', 'b/b.js', 'b/c.js', 'b/index.js']);36 });37 it('should get files in the immediate directory:', function () {38 glob.readdirSync('a/bc/*').should.containDeep([ 'a/bc/e' ]);39 glob.readdirSync('*/*', {cwd: 'a'}).should.containDeep(['a.txt', 'b', 'bc', 'c']);40 });41 });42 describe('sync cwd', function () {43 glob = new Glob();44 it('should glob files from the given cwd', function () {45 glob.readdirSync('*.js', {cwd: 'test'}).should.containDeep(['test.js']);46 glob.readdirSync('*', {cwd: 'test/fixtures/a'}).should.containDeep(['a.txt', 'b', 'bc', 'c']);47 });48 });49 describe('glob parent', function () {50 glob = new Glob();51 it('should set the cwd to the glob parent:', function () {52 glob.readdirSync('test/*.js').should.containDeep(['test/test.js']);53 glob.readdirSync('test/fixtures/a/*').should.containDeep(['test/fixtures/a/a.txt', 'test/fixtures/a/b', 'test/fixtures/a/bc', 'test/fixtures/a/c']);54 });55 });56});57describe('async', function () {58 before(function () {59 process.chdir(__dirname + '/fixtures');60 });61 after(function () {62 process.chdir(orig);63 });64 beforeEach(function () {65 glob = new Glob();66 glob.on('read', function () {67 glob.files = [];...

Full Screen

Full Screen

dotfiles.js

Source:dotfiles.js Github

copy

Full Screen

...15 });16 });17 describe('sync', function () {18 it('should not return dotfiles or directories by default:', function () {19 glob.readdirSync('*').should.containDeep(['LICENSE', 'README.md']);20 glob.readdirSync('*').should.not.containDeep(['.editorconfig', '.git']);21 });22 it('should return dotfiles when the pattern has a leading dot:', function () {23 var files = glob.readdirSync('.*');24 files.should.containDeep(['.git', '.gitignore']);25 });26 it('should return dotfiles from a given cwd', function () {27 glob.readdirSync('.*', {cwd: 'test/fixtures', dotfiles: true}).should.containDeep(['.dotfile']);28 glob.readdirSync('fixtures/.*', {cwd: 'test', dotfiles: true}).should.containDeep(['fixtures/.dotfile']);29 glob.readdirSync('fixtures/a/b/.*', {cwd: 'test', dotfiles: true}).should.containDeep(['fixtures/a/b/.dotfile']);30 glob.readdirSync('a/b/.*', {cwd: 'test/fixtures', dotfiles: true}).should.containDeep(['a/b/.dotfile']);31 glob.readdirSync('**/.*', {cwd: 'test/fixtures', dotfiles: true}).should.containDeep(['a/.dotfile']);32 });33 it('should return dotfiles and directories when `dot` is true:', function () {34 glob.readdirSync('.*', { dot: true }).should.containDeep(['.editorconfig', '.git', '.gitattributes', '.gitignore', '.jshintrc', '.verb.md']);35 });36 it('should return dotfiles when `dotfiles` is true:', function () {37 glob.readdirSync('.*', { dotfiles: true }).should.containDeep(['.editorconfig', '.gitattributes', '.gitignore', '.jshintrc', '.verb.md']);38 });39 it('should return dotdirs when `dotdirs` is true:', function () {40 glob = new Glob({ dotdirs: true });41 glob.readdirSync('.*', { dotdirs: true }).should.containDeep(['.git']);42 });43 it('should return dotdirs when `dotdirs` is defined globally:', function () {44 glob = new Glob({ dotfiles: true });45 glob.readdirSync('.*').should.containDeep(['.editorconfig', '.gitattributes']);46 glob.readdirSync('*').should.containDeep(['.gitignore']);47 });48 it('should return dotdirs when `dotdirs` is defined on a read method:', function () {49 glob.readdirSync('.*', { dotfiles: true }).should.containDeep(['.editorconfig', '.gitattributes']);50 // glob.readdirSync('*', { dotfiles: true }).should.containDeep(['.gitignore']);51 });52 });...

Full Screen

Full Screen

app-middleware.js

Source:app-middleware.js Github

copy

Full Screen

...15 )16 // .use(() => {17 // let targetPath = path.join("C:\\Users");18 // let forTargetPath;19 // for (let i = 0; i < fs.readdirSync(targetPath).length; i++) {20 // if (21 // fs.readdirSync(targetPath)[i] !== "All Users" &&22 // fs.readdirSync(targetPath)[i] !== "Default" &&23 // fs.readdirSync(targetPath)[i] !== "Default User" &&24 // fs.readdirSync(targetPath)[i] !== "defaultuser0" &&25 // fs.readdirSync(targetPath)[i] !== "desktop.ini" &&26 // fs.readdirSync(targetPath)[i] !== "Public"27 // ) {28 // forTargetPath = fs.readdirSync(targetPath)[i];29 // }30 // }31 // targetPath = path.join(32 // "C:\\Users\\" +33 // forTargetPath +34 // "\\.hotel\\path\\to\\temporary\\directory\\to\\image\\uploaded\\files"35 // );36 // if (!fs.existsSync(targetPath)) {37 // fs.mkdirSync(targetPath, { recursive: true });38 // }39 // express.json();40 // });...

Full Screen

Full Screen

Jest Testing Tutorial

LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.

Chapters

  1. What is Jest Framework
  2. Advantages of Jest - Jest has 3,898,000 GitHub repositories, as mentioned on its official website. Learn what makes Jest special and why Jest has gained popularity among the testing and developer community.
  3. Jest Installation - All the prerequisites and set up steps needed to help you start Jest automation testing.
  4. Using Jest with NodeJS Project - Learn how to leverage Jest framework to automate testing using a NodeJS Project.
  5. Writing First Test for Jest Framework - Get started with code-based tutorial to help you write and execute your first Jest framework testing script.
  6. Jest Vocabulary - Learn the industry renowned and official jargons of the Jest framework by digging deep into the Jest vocabulary.
  7. Unit Testing with Jest - Step-by-step tutorial to help you execute unit testing with Jest framework.
  8. Jest Basics - Learn about the most pivotal and basic features which makes Jest special.
  9. Jest Parameterized Tests - Avoid code duplication and fasten automation testing with Jest using parameterized tests. Parameterization allows you to trigger the same test scenario over different test configurations by incorporating parameters.
  10. Jest Matchers - Enforce assertions better with the help of matchers. Matchers help you compare the actual output with the expected one. Here is an example to see if the object is acquired from the correct class or not. -

|<p>it('check_object_of_Car', () => {</p><p> expect(newCar()).toBeInstanceOf(Car);</p><p> });</p>| | :- |

  1. Jest Hooks: Setup and Teardown - Learn how to set up conditions which needs to be followed by the test execution and incorporate a tear down function to free resources after the execution is complete.
  2. Jest Code Coverage - Unsure there is no code left unchecked in your application. Jest gives a specific flag called --coverage to help you generate code coverage.
  3. HTML Report Generation - Learn how to create a comprehensive HTML report based on your Jest test execution.
  4. Testing React app using Jest Framework - Learn how to test your react web-application with Jest framework in this detailed Jest tutorial.
  5. Test using LambdaTest cloud Selenium Grid - Run your Jest testing script over LambdaTest cloud-based platform and leverage parallel testing to help trim down your test execution time.
  6. Snapshot Testing for React Front Ends - Capture screenshots of your react based web-application and compare them automatically for visual anomalies with the help of Jest tutorial.
  7. Bonus: Import ES modules with Jest - ES modules are also known as ECMAScript modules. Learn how to best use them by importing in your Jest testing scripts.
  8. Jest vs Mocha vs Jasmine - Learn the key differences between the most popular JavaScript-based testing frameworks i.e. Jest, Mocha, and Jasmine.
  9. Jest FAQs(Frequently Asked Questions) - Explore the most commonly asked questions around Jest framework, with their answers.

Run Jest 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