Best JavaScript code snippet using mocha
resolver.spec.js
Source:resolver.spec.js
...64 });65 it('should find dependencies', function () {66 // this should _actually work_; no magic stubs here67 expect(68 resolveDependencies(resolveFixturePath('index.fixture.ts'), {69 tsConfigPath: resolveFixturePath('tsconfig.fixture.json'),70 cwd: path.join(__dirname, '..', '..'),71 }),72 'to satisfy',73 new Set([/debug/, /tsconfig\.fixture\.json/])74 );75 });76 it('should not look for a default TS config file', function () {77 expect(stubs.existsSync, 'was not called');78 });79 });80 describe('when not provided a path to TS config file', function () {81 describe('when file contains a missing module', function () {82 let result;83 beforeEach(function () {84 result = resolveDependencies(85 resolveFixturePath('unknown-dep.fixture.ts')86 );87 });88 it('should return an empty set', function () {89 expect(result, 'to be empty');90 });91 });92 describe('when TS config file not in `cwd`', function () {93 beforeEach(function () {94 resolveDependencies(resolveFixturePath('index.fixture.ts'));95 });96 it('should look for a TS config file in cwd', function () {97 expect(stubs.existsSync, 'to have a call satisfying', [98 path.join(process.cwd(), constants.DEFAULT_TS_CONFIG_FILENAME),99 ]);100 });101 });102 describe('when TS config file is in `cwd`', function () {103 beforeEach(function () {104 stubs.existsSync.returns(true);105 });106 it('should use the found TS config file', function () {107 const fixture = resolveFixturePath('index.fixture.ts');108 expect(109 resolveDependencies(fixture, {110 cwd: path.dirname(fixture), // cwd is needed to find default config file111 }),112 'to satisfy',113 new Set([114 /node_modules\/debug/,115 new RegExp(116 escapeStringRegexp(constants.DEFAULT_TS_CONFIG_FILENAME)117 ),118 ])119 );120 });121 });122 });123 });124 describe('when provided a JavaScript file', function () {125 describe('when file contains a syntax error', function () {126 let result;127 beforeEach(function () {128 result = resolveDependencies(resolveFixturePath('syntax.fixture.js'));129 });130 it('should return an empty set', function () {131 expect(result, 'to be empty');132 });133 });134 describe('when not provided a path to a Webpack config file', function () {135 let result;136 let fixture;137 beforeEach(function () {138 fixture = resolveFixturePath('webpack.fixture.js');139 result = resolveDependencies(fixture, {140 cwd: path.dirname(fixture), // cwd is needed to find the default config file141 });142 });143 it('should resolve non-relative modules from nearest module directory', function () {144 // this differs from the test using webpack.config.fixture.js, which points145 // to a specific module directory in the fixture dir (`mode_nodules`) and has146 // a different `debug`147 expect(148 result,149 'to satisfy',150 new Set([/node_modules\/debug/, /webpack-dep\.fixture\.js/])151 );152 });153 it('should look for a Webpack config file in cwd', function () {154 expect(stubs.existsSync, 'to have a call satisfying', [155 new RegExp(escapeRegexp(constants.DEFAULT_WEBPACK_CONFIG_FILENAME)),156 ]);157 });158 });159 describe('when provided a path to a Webpack config file', function () {160 let result;161 beforeEach(function () {162 stubs.existsSync.returns(true);163 const fixture = resolveFixturePath('webpack.fixture.js');164 result = resolveDependencies(fixture, {165 webpackConfigPath: resolveFixturePath('webpack.config.fixture.js'),166 });167 });168 it('should not look for a default Webpack config file', function () {169 expect(stubs.existsSync, 'not to have calls satisfying', [170 constants.DEFAULT_WEBPACK_CONFIG_FILENAME,171 ]);172 });173 it('should find dependencies as declared by webpack config', function () {174 expect(175 result,176 'to satisfy',177 new Set([178 new RegExp(escapeRegexp(constants.DEFAULT_WEBPACK_CONFIG_FILENAME)),179 /mode_nodules\/debug/,180 /webpack-dep\.fixture\.js/,181 ])182 );183 });184 });185 describe('when a default Webpack config file is in `cwd`', function () {186 beforeEach(function () {187 stubs.existsSync.returns(true);188 });189 it('should use the found Webpack config file', function () {190 expect(191 resolveDependencies(192 resolveFixturePath('webpack.fixture.js'),193 // change cwd to the directory of the fixture webpack config file194 {cwd: path.join(__dirname, 'fixtures')}195 ),196 'to satisfy',197 new Set([198 /webpack-dep\.fixture\.js/,199 /debug/,200 new RegExp(escapeRegexp(constants.DEFAULT_WEBPACK_CONFIG_FILENAME)),201 ])202 );203 });204 });205 });206 describe('ignored dependencies', function () {...
global-fixtures.spec.js
Source:global-fixtures.spec.js
...14 it('should execute global setup and teardown', async function() {15 return expect(16 runMochaAsync(DEFAULT_FIXTURE, [17 '--require',18 resolveFixturePath('plugins/global-fixtures/global-setup-teardown')19 ]),20 'when fulfilled',21 'to have passed'22 );23 });24 describe('when only global teardown is supplied', function() {25 it('should run global teardown', async function() {26 return expect(27 runMochaAsync(DEFAULT_FIXTURE, [28 '--require',29 resolveFixturePath('plugins/global-fixtures/global-teardown')30 ]),31 'when fulfilled',32 'to contain once',33 /teardown schmeardown/34 );35 });36 });37 describe('when only global setup is supplied', function() {38 it('should run global setup', async function() {39 return expect(40 runMochaAsync(DEFAULT_FIXTURE, [41 '--require',42 resolveFixturePath('plugins/global-fixtures/global-setup')43 ]),44 'when fulfilled',45 'to contain once',46 /setup schmetup/47 );48 });49 });50 it('should share context', async function() {51 return expect(52 runMochaAsync(DEFAULT_FIXTURE, [53 '--require',54 resolveFixturePath('plugins/global-fixtures/global-setup-teardown')55 ]),56 'when fulfilled',57 'to contain once',58 /setup: this\.foo = bar[\s\S]+teardown: this\.foo = bar/59 );60 });61 describe('when supplied multiple functions', function() {62 it('should execute them sequentially', async function() {63 return expect(64 runMochaAsync(DEFAULT_FIXTURE, [65 '--require',66 resolveFixturePath(67 'plugins/global-fixtures/global-setup-teardown-multiple'68 )69 ]),70 'when fulfilled',71 'to contain once',72 /teardown: this.foo = 3/73 );74 });75 });76 describe('when run in watch mode', function() {77 let tempDir;78 let testFile;79 let removeTempDir;80 beforeEach(async function() {81 const tempInfo = await createTempDir();82 tempDir = tempInfo.dirpath;83 removeTempDir = tempInfo.removeTempDir;84 testFile = path.join(tempDir, 'test.js');85 copyFixture(DEFAULT_FIXTURE, testFile);86 });87 afterEach(async function() {88 if (removeTempDir) {89 return removeTempDir();90 }91 });92 it('should execute global setup and teardown', async function() {93 return expect(94 runMochaWatchAsync(95 [96 '--require',97 resolveFixturePath(98 'plugins/global-fixtures/global-setup-teardown'99 ),100 testFile101 ],102 tempDir,103 () => {104 touchFile(testFile);105 }106 ),107 'when fulfilled',108 'to have passed'109 );110 });111 describe('when only global teardown is supplied', function() {112 it('should run global teardown', async function() {113 return expect(114 runMochaWatchAsync(115 [116 '--require',117 resolveFixturePath('plugins/global-fixtures/global-teardown'),118 testFile119 ],120 tempDir,121 () => {122 touchFile(testFile);123 }124 ),125 'when fulfilled',126 'to contain once',127 /teardown schmeardown/128 );129 });130 });131 describe('when only global setup is supplied', function() {132 it('should run global setup', async function() {133 return expect(134 runMochaWatchAsync(135 [136 '--require',137 resolveFixturePath('plugins/global-fixtures/global-setup'),138 testFile139 ],140 tempDir,141 () => {142 touchFile(testFile);143 }144 ),145 'when fulfilled',146 'to contain once',147 /setup schmetup/148 );149 });150 });151 it('should not re-execute the global fixtures', async function() {152 return expect(153 runMochaWatchAsync(154 [155 '--require',156 resolveFixturePath(157 'plugins/global-fixtures/global-setup-teardown-multiple'158 ),159 testFile160 ],161 tempDir,162 () => {163 touchFile(testFile);164 }165 ),166 'when fulfilled',167 'to contain once',168 /teardown: this.foo = 3/169 );170 });171 });172 });173 describe('when mocha run in parallel mode', function() {174 it('should execute global setup and teardown', async function() {175 return expect(176 runMochaAsync(DEFAULT_FIXTURE, [177 '--parallel',178 '--require',179 resolveFixturePath('plugins/global-fixtures/global-setup-teardown')180 ]),181 'when fulfilled',182 'to have passed'183 );184 });185 it('should share context', async function() {186 return expect(187 runMochaAsync(DEFAULT_FIXTURE, [188 '--parallel',189 '--require',190 resolveFixturePath('plugins/global-fixtures/global-setup-teardown')191 ]),192 'when fulfilled',193 'to contain once',194 /setup: this.foo = bar/195 ).and('when fulfilled', 'to contain once', /teardown: this.foo = bar/);196 });197 describe('when supplied multiple functions', function() {198 it('should execute them sequentially', async function() {199 return expect(200 runMochaAsync(DEFAULT_FIXTURE, [201 '--parallel',202 '--require',203 resolveFixturePath(204 'plugins/global-fixtures/global-setup-teardown-multiple'205 )206 ]),207 'when fulfilled',208 'to contain once',209 /teardown: this.foo = 3/210 );211 });212 });213 describe('when run in watch mode', function() {214 let tempDir;215 let testFile;216 let removeTempDir;217 beforeEach(async function() {218 const tempInfo = await createTempDir();219 tempDir = tempInfo.dirpath;220 removeTempDir = tempInfo.removeTempDir;221 testFile = path.join(tempDir, 'test.js');222 copyFixture(DEFAULT_FIXTURE, testFile);223 });224 afterEach(async function() {225 if (removeTempDir) {226 return removeTempDir();227 }228 });229 it('should execute global setup and teardown', async function() {230 return expect(231 runMochaWatchAsync(232 [233 '--parallel',234 '--require',235 resolveFixturePath(236 'plugins/global-fixtures/global-setup-teardown'237 ),238 testFile239 ],240 tempDir,241 () => {242 touchFile(testFile);243 }244 ),245 'when fulfilled',246 'to have passed'247 );248 });249 it('should not re-execute the global fixtures', async function() {250 return expect(251 runMochaWatchAsync(252 [253 '--parallel',254 '--require',255 resolveFixturePath(256 'plugins/global-fixtures/global-setup-teardown-multiple'257 ),258 testFile259 ],260 tempDir,261 () => {262 touchFile(testFile);263 }264 ),265 'when fulfilled',266 'to contain once',267 /teardown: this.foo = 3/268 );269 });...
project.spec.js
Source:project.spec.js
...5const project = require('../lib/project');6const pkg = require('../package.json');7describe('project', () => {8 it('should reject when project dir not in expected format', () => {9 const p = helpers.resolveFixturePath('a-project');10 expect.assertions(2);11 return project(p, models)12 .catch((err) => {13 expect(err.message).toBe('Expected project dir to be in 00-slug format and got a-project');14 expect(err.path).toBe(p);15 });16 });17 it('should reject when language not supported', () => {18 const p = helpers.resolveFixturePath('01-foo');19 expect.assertions(1);20 return project(p, models, {21 track: 'js',22 repo: 'Laboratoria/bootcamp',23 version: '1.0.0',24 locale: 'en-GB',25 })26 .catch((err) => {27 expect(err.message).toBe('Unsupported language: en');28 });29 });30 it('should reject when dir doesnt exist', () => {31 expect.assertions(2);32 return project('01-foo', models, { locale: 'es-ES' })33 .catch((err) => {34 expect(err.message).toMatch(/no such file or directory/);35 expect(err.code).toBe('ENOENT');36 });37 });38 it('should reject when README.md is empty', () => {39 const p = helpers.resolveFixturePath('00-course-empty');40 expect.assertions(2);41 return project(p, models, { locale: 'es-ES' })42 .catch((err) => {43 expect(err.message).toBe('Project README.md is empty');44 expect(err.path).toBe(path.join(p, 'README.md'));45 });46 });47 it('should reject when README.md doesnt start with h1', () => {48 const p = helpers.resolveFixturePath('01-a-project-without-a-title');49 const p2 = helpers.resolveFixturePath('01-a-project-without-a-bad-title');50 return project(p, models, { locale: 'es-ES' })51 .then(() => {52 throw new Error('This should never happen');53 })54 .catch((err) => {55 expect(err.message).toBe('Expected README.md to start with h1 and instead saw heading (depth: 2)');56 expect(err.path).toBe(path.join(p, 'README.md'));57 return project(p2, models, { locale: 'es-ES' });58 })59 .then(() => {60 throw new Error('This should never happen');61 })62 .catch((err) => {63 expect(err.message).toBe('Expected README.md to start with h1 and instead saw paragraph');64 expect(err.path).toBe(path.join(p2, 'README.md'));65 });66 });67 it('should parse portuguese project', () => {68 const p = helpers.resolveFixturePath('01-a-project-with-pt-translation');69 return project(p, models, {70 track: 'js',71 repo: 'Laboratoria/bootcamp',72 version: '1.0.0',73 locale: 'pt-BR',74 suffix: 'pt',75 })76 .then(({ createdAt, ...parsed }) => {77 expect(parsed.slug).toBe('a-project-with-pt-translation-pt');78 expect(parsed.locale).toBe('pt-BR');79 expect(parsed).toMatchSnapshot();80 });81 });82 it('should reject when unknown learning objective', () => {83 const p = helpers.resolveFixturePath('01-a-project-with-unknown-learning-objective');84 expect.assertions(2);85 return project(p, models, {86 track: 'js',87 repo: 'Laboratoria/bootcamp',88 version: '1.0.0',89 locale: 'es-ES',90 lo: path.join(__dirname, 'fixtures', 'learning-objectives'),91 })92 .catch((err) => {93 expect(err.message).toBe('Unknown learning objectives: html/foo.');94 expect(err.path).toBe(path.join(p, 'README.md'));95 });96 });97 it('should parse a project with learning objectives without validating against known list', () => {98 const p = helpers.resolveFixturePath('01-a-project-with-learning-objectives');99 return project(p, models, {100 track: 'js',101 repo: 'Laboratoria/bootcamp',102 version: '1.0.0',103 locale: 'es-ES',104 })105 .then(({ parserVersion, createdAt, ...parsed }) => {106 expect(parserVersion).toBe(pkg.version);107 expect(parsed).toMatchSnapshot();108 });109 });110 it('should parse a project with learning objectives validating against known list', () => {111 const p = helpers.resolveFixturePath('01-a-project-with-learning-objectives');112 return project(p, models, {113 track: 'js',114 repo: 'Laboratoria/bootcamp',115 version: '1.0.0',116 locale: 'es-ES',117 lo: path.join(__dirname, 'fixtures', 'learning-objectives'),118 })119 .then(({ parserVersion, createdAt, ...parsed }) => {120 expect(parserVersion).toBe(pkg.version);121 expect(parsed).toMatchSnapshot();122 });123 });124 it('should parse a project with learning objectives', () => {125 const p = helpers.resolveFixturePath('01-a-project-with-learning-objectives');126 return project(p, models, {127 track: 'js',128 repo: 'Laboratoria/bootcamp',129 version: '1.0.0',130 locale: 'es-ES',131 })132 .then(({ parserVersion, createdAt, ...parsed }) => {133 expect(parserVersion).toBe(pkg.version);134 expect(parsed).toMatchSnapshot();135 });136 });137 it('should expand learning objectives children when only parent is mentioned', () => {138 const p = helpers.resolveFixturePath('01-a-project-with-lo-needing-expansion');139 return project(p, models, {140 track: 'js',141 repo: 'Laboratoria/bootcamp',142 version: '1.0.0',143 locale: 'es-ES',144 lo: path.join(__dirname, 'fixtures', 'learning-objectives'),145 })146 .then((result) => {147 expect(result.learningObjectives).toMatchSnapshot();148 });149 });...
course.spec.js
Source:course.spec.js
...10 expect(err.code).toBe('ENOENT');11 })12 ));13 it('should reject when README.md is empty', () => (14 course(helpers.resolveFixturePath('00-course-empty'), models, {15 track: 'js',16 locale: 'es-ES',17 })18 .catch((err) => {19 expect(err.message).toBe('README.md del curso está vacÃo');20 expect(err.path).toBe(helpers.resolveFixtureDirReadmePath('00-course-empty'));21 })22 ));23 it('should reject when README.md doesnt start with h1', () => (24 course(helpers.resolveFixturePath('01-course-no-title'), models, {25 track: 'js',26 locale: 'es-ES',27 })28 .catch((err) => {29 expect(err.message).toBe('README.md del curso debe empezar con un h1 con el tÃtulo del curso');30 expect(err.path).toBe(helpers.resolveFixtureDirReadmePath('01-course-no-title'));31 })32 ));33 it('should have empty tags if not found', () => (34 course(helpers.resolveFixturePath('02-course-no-tags'), models, {35 repo: 'Laboratoria/bootcamp',36 version: '2.0.0',37 track: 'js',38 locale: 'es-ES',39 })40 .then(data => expect(data.tags).toMatchSnapshot())41 ));42 it('should read primary (default) tags', () => (43 course(helpers.resolveFixturePath('02-course-tags'), models, {44 repo: 'Laboratoria/bootcamp',45 version: '2.0.0',46 track: 'js',47 locale: 'es-ES',48 })49 .then(data => expect(data.tags).toMatchSnapshot())50 ));51 it('should read main and secondary tags', () => (52 course(helpers.resolveFixturePath('02-course-secondary-tags'), models, {53 repo: 'Laboratoria/bootcamp',54 version: '2.0.0',55 track: 'js',56 locale: 'es-ES',57 })58 .then(data => expect(data.tags).toMatchSnapshot())59 ));60 it('should parse with target audience', () => (61 course(helpers.resolveFixturePath('02-course-with-target-audience'), models, {62 repo: 'Laboratoria/bootcamp',63 version: '2.0.0',64 track: 'js',65 locale: 'es-ES',66 })67 .then((data) => {68 expect(data.tags).toMatchSnapshot();69 expect(data.targetAudience).toMatchSnapshot();70 })71 ));72 it('should parse grades (evaluación) section', () => (73 course(helpers.resolveFixturePath('03-course-with-grades'), models, {74 repo: 'Laboratoria/bootcamp',75 version: '2.0.0',76 track: 'js',77 locale: 'es-ES',78 })79 .then(data => expect(data.grades).toMatchSnapshot())80 ));81 it('should trim <hr> from html fragments', () => (82 course(helpers.resolveFixturePath('03-course-with-grades'), models, {83 repo: 'Laboratoria/bootcamp',84 version: '2.0.0',85 track: 'js',86 locale: 'es-ES',87 })88 .then(data => expect(data.product).toMatchSnapshot())89 ));90 it('should validate units and parts', () => (91 course(helpers.resolveFixturePath('course-with-invalid-unit'), models, {92 repo: 'Laboratoria/bootcamp',93 version: '2.0.0',94 track: 'js',95 locale: 'es-ES',96 })97 .catch((err) => {98 expect(err.name).toBe('ValidationError');99 expect(err.message)100 .toBe('TopicUnitPart validation failed: type: Path `type` is required.');101 })102 ));103 it('should ignore tables in course description (taken from course readme)', () => (104 course(helpers.resolveFixturePath('00-course-with-part-tables'), models, {105 repo: 'Laboratoria/bootcamp',106 version: '2.0.0',107 track: 'js',108 locale: 'es-ES',109 })110 .then(result => expect(result.syllabus).toMatchSnapshot())111 ));...
helpers.js
Source:helpers.js
...24 * @param {Function} done - Callback25 */26 runMocha: function(fixturePath, args, done) {27 var path;28 path = resolveFixturePath(fixturePath);29 args = args || [];30 invokeMocha(args.concat(['-C', path]), function(err, res) {31 if (err) {32 return done(err);33 }34 done(null, getSummary(res));35 });36 },37 /**38 * Invokes the mocha binary for the given fixture using the JSON reporter,39 * returning the parsed output, as well as exit code.40 *41 * @param {string} fixturePath - Path from __dirname__42 * @param {string[]} args - Array of args43 * @param {Function} fn - Callback44 */45 runMochaJSON: function(fixturePath, args, fn) {46 var path;47 path = resolveFixturePath(fixturePath);48 args = args || [];49 return invokeMocha(args.concat(['--reporter', 'json', path]), function(50 err,51 res52 ) {53 if (err) return fn(err);54 try {55 var result = JSON.parse(res.output);56 result.code = res.code;57 } catch (err) {58 return fn(err);59 }60 fn(null, result);61 });62 },63 /**64 * regular expression used for splitting lines based on new line / dot symbol.65 */66 splitRegExp: new RegExp('[\\n' + baseReporter.symbols.dot + ']+'),67 /**68 * Invokes the mocha binary. Accepts an array of additional command line args69 * to pass. The callback is invoked with the exit code and output. Optional70 * current working directory as final parameter.71 *72 * In most cases runMocha should be used instead.73 *74 * Example response:75 * {76 * code: 1,77 * output: '...'78 * }79 *80 * @param {Array<string>} args - Extra args to mocha executable81 * @param {Function} done - Callback82 * @param {string} cwd - Current working directory for mocha run, optional83 */84 invokeMocha: invokeMocha,85 /**86 * Resolves the path to a fixture to the full path.87 */88 resolveFixturePath: resolveFixturePath89};90function invokeMocha(args, fn, cwd) {91 var output, mocha, listener;92 output = '';93 args = [path.join(__dirname, '..', '..', 'bin', 'mocha')].concat(args);94 mocha = spawn(process.execPath, args, {cwd: cwd});95 listener = function(data) {96 output += data;97 };98 mocha.stdout.on('data', listener);99 mocha.stderr.on('data', listener);100 mocha.on('error', fn);101 mocha.on('close', function(code) {102 fn(null, {103 output: output.split('\n').join('\n'),104 code: code105 });106 });107 return mocha;108}109function resolveFixturePath(fixture) {110 return path.join('./test/integration/fixtures', fixture);111}112function getSummary(res) {113 return ['passing', 'pending', 'failing'].reduce(function(summary, type) {114 var pattern, match;115 pattern = new RegExp(' (\\d+) ' + type + '\\s');116 match = pattern.exec(res.output);117 summary[type] = match ? parseInt(match, 10) : 0;118 return summary;119 }, res);...
npm-helper.spec.js
Source:npm-helper.spec.js
...17 if (lernaFilepath != null) {18 fs.moveSync(lernaFilepath, bakFilepath)19 }20 try {21 expect(detectMonorepo(resolveFixturePath('monorepo1'))).toBeTruthy()22 expect(detectMonorepo(resolveFixturePath('monorepo2'))).toBeTruthy()23 expect(detectMonorepo(resolveFixturePath('normal-repo'))).toBeFalsy()24 } finally {25 if (lernaFilepath != null) {26 fs.moveSync(bakFilepath, lernaFilepath)27 }28 }29 })30 test('detectPackageAuthor', function () {31 expect(detectPackageAuthor(__dirname)).toEqual('guanghechen')32 expect(detectPackageAuthor(resolveFixturePath('monorepo1'))).toEqual('guanghechen')33 expect(detectPackageAuthor(resolveFixturePath('monorepo2'))).toEqual('waw')34 expect(detectPackageAuthor(resolveFixturePath('normal-repo'))).toBeNull()35 })36})37describe('dependency', function () {38 test('createDependencyFields', function () {39 expect(createDependencyFields()).toEqual([40 'dependencies',41 'optionalDependencies',42 'peerDependencies',43 ])44 })45 test('collectAllDependencies', function () {46 expect(collectAllDependencies(path.join(__dirname, '../package.json'))).toMatchSnapshot(47 'current repo',48 )49 expect(50 collectAllDependencies(51 resolveFixturePath('monorepo2/package.json'),52 undefined,53 ['rollup'],54 () => true,55 ),56 ).toMatchSnapshot('monorepo2')57 const warningDataList = []58 const warnSpy = jest59 .spyOn(console, 'warn')60 .mockImplementation((...args) => void warningDataList.push(...args))61 expect(62 collectAllDependencies(resolveFixturePath('normal-repo/package.json'), ['peerDependencies']),63 ).toMatchSnapshot('normal-repo')64 expect(warningDataList).toMatchSnapshot('normal-repo -- warnings')65 warnSpy.mockRestore()66 })...
threaded-module-map.spec.js
Source:threaded-module-map.spec.js
...9const resolveFixturePath = (filename) =>10 path.join(__dirname, 'fixtures', 'module-map', filename);11const TEST_MODULE_MAP_CACHE_FILENAME = 'module-map-integration-test.cache.json';12const TEST_FILE_ENTRY_CACHE_FILENAME = 'file-entry-integration-test.cache.json';13const TEST_WITH_DEP_PATH = resolveFixturePath(14 'test-with-dependency.fixture.js'15);16const DEP_PATH = resolveFixturePath('dependency.fixture.js');17const TEST_WITH_TRANSITIVE_DEP_PATH = resolveFixturePath(18 'test-with-transitive-dep.fixture.js'19);20const TRANSITIVE_DEP_PATH = resolveFixturePath('transitive-dep.fixture.js');21describe('threaded-module-map', function () {22 /**23 * @type {ThreadedModuleMap}24 */25 let tmm;26 beforeEach(async function () {27 tmm = ThreadedModuleMap.create({28 fileEntryCacheFilename: TEST_FILE_ENTRY_CACHE_FILENAME,29 moduleMapCacheFilename: TEST_MODULE_MAP_CACHE_FILENAME,30 entryFiles: [TEST_WITH_DEP_PATH, TEST_WITH_TRANSITIVE_DEP_PATH],31 reset: true,32 });33 return Promise.all([tmm._online, tmm.ready]);34 });...
integration.run.js
Source:integration.run.js
1import path from 'path';2import { oneLine } from 'common-tags';3import { executeScript } from '../helpers';4const expectedResult = '"summary":{"errors":0,"notices":0,"warnings":0}';5function resolveFixturePath(fixtureName) {6 return path.resolve(__dirname, '..', '..', 'fixtures', fixtureName);7}8describe('Integration/smoke tests', () => {9 it('should pass if ran on a simple valid extension', async () => {10 const fixture = resolveFixturePath('webextension_es6_module');11 const { exitCode, stderr, stdout } = await executeScript('addons-linter', [12 '-o',13 'json',14 fixture,15 ]);16 expect(stdout).toContain(expectedResult);17 expect(stderr).toStrictEqual('');18 expect(exitCode).toEqual(0);19 });20 it('should ignore .eslintignore files', async () => {21 const fixture = resolveFixturePath('webextension_with_eslintignore');22 const { exitCode, stderr, stdout } = await executeScript(23 'addons-linter',24 ['-o', 'json', fixture],25 {26 // .eslintignore file has to be in the current directory27 // to be loaded by eslint in its default config.28 cwd: fixture,29 }30 );31 expect(stdout).toContain(expectedResult);32 expect(stderr).toStrictEqual('');33 expect(exitCode).toEqual(0);34 });35 it('should pass if ran on a simple valid CRX extension', async () => {36 const fixture = resolveFixturePath('crx3.crx');37 const { exitCode, stderr, stdout } = await executeScript('addons-linter', [38 '-o',39 'json',40 fixture,41 ]);42 expect(stdout).toContain('"summary":{"errors":0,"notices":0,"warnings":1}');43 expect(stderr).toStrictEqual('');44 expect(exitCode).toEqual(0);45 });46 it('should log the expected error message on invalid --min/max-manifest-version range', async () => {47 const fixture = resolveFixturePath('webextension_es6_module');48 const { exitCode, stderr } = await executeScript('addons-linter', [49 '--min-manifest-version=3',50 '--max-manifest-version=2',51 fixture,52 ]);53 const expectedMessage = oneLine`54 Invalid manifest version range requested:55 --min-manifest-version (currently set to 3)56 should not be greater than57 --max-manifest-version (currently set to 2).58 `;59 expect(stderr).toStrictEqual(`${expectedMessage}\n`);60 expect(exitCode).toEqual(2);61 });...
Using AI Code Generation
1const path = require("path");2const mocha = require("mocha");3const mochaOptions = {4};5const mochaInstance = new mocha(mochaOptions);6mochaInstance.addFile(path.resolve(__dirname, "./test.spec.js"));7mochaInstance.run((failures) => {8 process.exitCode = failures ? 1 : 0;9});10"scripts": {11 },12"scripts": {13 },
Using AI Code Generation
1var Mocha = require('mocha');2var mocha = new Mocha();3var path = mocha.resolveFixturePath('path/to/fixture.js');4console.log(path);5### mocha.addFile(file)6### mocha.reporter(name, reporterOptions)7### mocha.grep(value)8### mocha.invert()9### mocha.ignoreLeaks(boolean)10### mocha.globals(value)11### mocha.checkLeaks()12### mocha.growl()13### mocha.useColors(boolean)14### mocha.useInlineDiffs(boolean)15### mocha.ui(name)16### mocha.bail(boolean)17### mocha.asyncOnly(boolean)18### mocha.noHighlighting(boolean)19### mocha.timeout(value)20### mocha.slow(value)
Using AI Code Generation
1var assert = require('assert');2var path = require('path');3var mocha = require('mocha');4var Mocha = mocha.Mocha;5var mocha = new Mocha();6var fixturePath = mocha.resolveFixturePath('fixtures', 'test.txt');7assert.equal(path.basename(fixturePath), 'test.txt');8assert.equal(path.basename(path.dirname(fixturePath)), 'fixtures');
Using AI Code Generation
1const { resolveFixturePath } = require('mocha/lib/cli/run-helpers');2const Mocha = require('mocha');3const mocha = new Mocha();4mocha.addFile(resolveFixturePath('test.js'));5mocha.run(failures => process.exitCode = failures ? 1 : 0);6describe('my suite', () => {7 it('my test', () => {8 assert.equal(1, 1);9 });10});11describe('my suite', () => {12 it('my test', () => {13 assert.equal(1, 1);14 });15});16describe('my suite', () => {17 it('my test', () => {18 assert.equal(1, 1);19 });20});21describe('my suite', () => {22 it('my test', () => {23 assert.equal(1, 1);24 });25});26describe('my suite', () => {27 it('my test', () => {28 assert.equal(1, 1);29 });30});
Using AI Code Generation
1var path = require('path');2var mocha = require('mocha');3var mocha = new mocha();4var testFile = mocha.resolveFixturePath(path.join('..', 'test', 'test.js'));5var Mocha = require('mocha'),6 fs = require('fs'),7 path = require('path');8var mocha = new Mocha({9});10fs.readdirSync(__dirname + '/test').filter(function(file){11 return file.substr(-3) === '.js';12}).forEach(function(file){13 mocha.addFile(14 path.join(__dirname, '/test', file)15 );16});17mocha.run(function(failures){18 process.on('exit', function () {19 });20});
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!!