How to use createPriorityPreprocessor method in Karma

Best JavaScript code snippet using karma

preprocessor.spec.js

Source:preprocessor.spec.js Github

copy

Full Screen

...33 fakePreprocessor = sinon.spy((content, file, done) => {34 file.path = file.path + '-preprocessed'35 done(null, 'new-content')36 })37 const pp = m.createPriorityPreprocessor({ '**/*.js': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)38 const file = { originalPath: '/some/a.js', path: 'path' }39 await pp(file)40 expect(fakePreprocessor).to.have.been.called41 expect(file.path).to.equal('path-preprocessed')42 expect(file.content).to.equal('new-content')43 })44 it('should match directories starting with a dot', async () => {45 fakePreprocessor = sinon.spy((content, file, done) => {46 file.path = file.path + '-preprocessed'47 done(null, 'new-content')48 })49 const pp = m.createPriorityPreprocessor({ '**/*.js': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)50 const file = { originalPath: '/some/.dir/a.js', path: 'path' }51 await pp(file)52 expect(fakePreprocessor).to.have.been.called53 expect(file.path).to.equal('path-preprocessed')54 expect(file.content).to.equal('new-content')55 })56 it('should get content if preprocessor is an async function or return Promise with content', async () => {57 fakePreprocessor = sinon.spy(async (content, file, done) => {58 file.path = file.path + '-preprocessed'59 return 'new-content'60 })61 const pp = m.createPriorityPreprocessor({ '**/*.js': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)62 const file = { originalPath: '/some/.dir/a.js', path: 'path' }63 await pp(file)64 expect(fakePreprocessor).to.have.been.called65 expect(file.path).to.equal('path-preprocessed')66 expect(file.content).to.equal('new-content')67 })68 it('should get content if preprocessor is an async function still calling done()', async () => {69 fakePreprocessor = sinon.spy(async (content, file, done) => {70 file.path = file.path + '-preprocessed'71 done(null, 'new-content')72 })73 const pp = m.createPriorityPreprocessor({ '**/*.js': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)74 const file = { originalPath: '/some/.dir/a.js', path: 'path' }75 await pp(file)76 expect(fakePreprocessor).to.have.been.called77 expect(file.path).to.equal('path-preprocessed')78 expect(file.content).to.equal('new-content')79 })80 it('should check patterns after creation when invoked', async () => {81 fakePreprocessor = sinon.spy((content, file, done) => {82 file.path = file.path + '-preprocessed'83 done(null, 'new-content')84 })85 const config = { '**/*.txt': ['fake'] }86 const pp = m.createPriorityPreprocessor(config, {}, null, simpleFakeInstantiatePlugin)87 const file = { originalPath: '/some/a.js', path: 'path' }88 config['**/*.js'] = ['fake']89 await pp(file)90 expect(fakePreprocessor).to.have.been.called91 expect(file.path).to.equal('path-preprocessed')92 expect(file.content).to.equal('new-content')93 })94 it('should ignore not matching file', async () => {95 fakePreprocessor = sinon.spy((content, file, done) => {96 done(null, '')97 })98 const pp = m.createPriorityPreprocessor({ '**/*.js': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)99 const file = { originalPath: '/some/a.txt', path: 'path' }100 await pp(file)101 expect(fakePreprocessor).to.not.have.been.called102 })103 it('should apply all preprocessors', async () => {104 const fakes = {105 fake1: sinon.spy((content, file, done) => {106 file.path = file.path + '-p1'107 done(null, content + '-c1')108 }),109 fake2: sinon.spy((content, file, done) => {110 file.path = file.path + '-p2'111 done(content + '-c2')112 })113 }114 function fakeInstatiatePlugin (kind, name) {115 return fakes[name]116 }117 const pp = m.createPriorityPreprocessor({ '**/*.js': ['fake1', 'fake2'] }, {}, null, fakeInstatiatePlugin)118 const file = { originalPath: '/some/a.js', path: 'path' }119 await pp(file)120 expect(fakes.fake1).to.have.been.calledOnce121 expect(fakes.fake2).to.have.been.calledOnce122 expect(file.path).to.equal('path-p1-p2')123 expect(file.content).to.equal('content-c1-c2')124 })125 it('should compute SHA', async () => {126 const pp = m.createPriorityPreprocessor({}, {}, null, simpleFakeInstantiatePlugin)127 const file = { originalPath: '/some/a.js', path: 'path' }128 await pp(file)129 expect(file.sha).to.exist130 expect(file.sha.length).to.equal(40)131 const previousSHA = file.sha132 await pp(file)133 expect(file.sha).to.equal(previousSHA)134 mockFs._touchFile('/some/a.js', null, 'new-content')135 await pp(file)136 expect(file.sha.length).to.equal(40)137 expect(file.sha).not.to.equal(previousSHA)138 })139 it('should compute SHA from content returned by a processor', async () => {140 fakePreprocessor = sinon.spy((content, file, done) => {141 done(null, content + '-processed')142 })143 const pp = m.createPriorityPreprocessor({ '**/a.js': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)144 const fileProcess = { originalPath: '/some/a.js', path: 'path' }145 const fileSkip = { originalPath: '/some/b.js', path: 'path' }146 await pp(fileProcess)147 await pp(fileSkip)148 expect(fileProcess.sha).to.exist149 expect(fileProcess.sha.length).to.equal(40)150 expect(fileSkip.sha).to.exist151 expect(fileSkip.sha.length).to.equal(40)152 expect(fileProcess.sha).not.to.equal(fileSkip.sha)153 })154 it('should return error if any preprocessor fails', () => {155 fakePreprocessor = sinon.spy((content, file, done) => {156 done(new Error('Some error'), null)157 })158 const pp = m.createPriorityPreprocessor({ '**/*.js': ['failing'] }, {}, null, simpleFakeInstantiatePlugin)159 const file = { originalPath: '/some/a.js', path: 'path' }160 return pp(file).then(() => {161 throw new Error('Should be failed')162 }, (err) => {163 expect(err).to.exist164 })165 })166 it('should stop preprocessing after an error', async () => {167 const fakes = {168 failing: sinon.spy((content, file, done) => {169 done(new Error('Some error'), null)170 }),171 fake: sinon.spy((content, file, done) => {172 done(null, content)173 })174 }175 function fakeInstantiatePlugin (kind, name) {176 return fakes[name]177 }178 const pp = m.createPriorityPreprocessor({ '**/*.js': ['failing', 'fake'] }, {}, null, fakeInstantiatePlugin)179 const file = { originalPath: '/some/a.js', path: 'path' }180 await pp(file).then(() => {181 throw new Error('should be failed')182 }, (err) => {183 expect(err.message).to.equal('Some error')184 })185 expect(fakes.fake).not.to.have.been.called186 })187 describe('when fs.readFile fails', () => {188 const file = { originalPath: '/some/a.js', path: 'path' }189 beforeEach(() => {190 sinon.stub(mockFs, 'readFileSync').throwsException('error')191 })192 it('should retry up to 3 times', async () => {193 fakePreprocessor = sinon.spy((content, file, done) => {194 done(null, content)195 })196 const pp = m.createPriorityPreprocessor({ '**/*.js': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)197 await pp(file).then(() => {198 throw new Error('Should be rejected')199 }, () => {200 // 3 times repeated and 1 the first execution201 expect(mockFs.readFileSync.callCount).to.equal(4)202 expect(fakePreprocessor.notCalled).to.be.true203 mockFs.readFileSync.restore()204 })205 })206 it('should throw after 3 retries', async () => {207 const pp = m.createPriorityPreprocessor({ '**/*.js': [] }, {}, null, simpleFakeInstantiatePlugin)208 await pp(file).then(() => {209 throw new Error('Should be rejected')210 }, () => {211 expect(mockFs.readFileSync.callCount).to.equal(4)212 mockFs.readFileSync.restore()213 })214 })215 })216 it('should not preprocess binary files by default', async () => {217 fakePreprocessor = sinon.spy((content, file, done) => {218 done(null, content)219 })220 const pp = m.createPriorityPreprocessor({ '**/*': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)221 const file = { originalPath: '/some/photo.png', path: 'path' }222 await pp(file)223 expect(fakePreprocessor).not.to.have.been.called224 expect(file.content).to.be.an.instanceof(Buffer)225 })226 it('should not preprocess files configured to be binary', async () => {227 fakePreprocessor = sinon.spy((content, file, done) => {228 done(null, content)229 })230 const pp = m.createPriorityPreprocessor({ '**/*': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)231 const file = { originalPath: '/some/proto.pb', path: 'path', isBinary: true }232 await pp(file)233 expect(fakePreprocessor).not.to.have.been.called234 expect(file.content).to.be.an.instanceof(Buffer)235 })236 it('should preprocess files configured not to be binary', async () => {237 fakePreprocessor = sinon.spy((content, file, done) => {238 done(null, content)239 })240 const pp = m.createPriorityPreprocessor({ '**/*': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)241 // Explicit false for isBinary242 const file = { originalPath: '/some/proto.pb', path: 'path', isBinary: false }243 await pp(file)244 expect(fakePreprocessor).to.have.been.calledOnce245 expect(typeof file.content).to.equal('string')246 })247 it('should preprocess binary files if handleBinaryFiles=true', async () => {248 fakePreprocessor = sinon.spy((content, file, done) => {249 done(null, content)250 })251 fakePreprocessor.handleBinaryFiles = true252 const pp = m.createPriorityPreprocessor({ '**/*': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)253 const file = { originalPath: '/some/photo.png', path: 'path' }254 await pp(file)255 expect(fakePreprocessor).to.have.been.calledOnce256 expect(file.content).to.be.an.instanceof(Buffer)257 })258 it('should not preprocess binary files with capital letters in extension', async () => {259 fakePreprocessor = sinon.spy((content, file, done) => {260 done(null, content)261 })262 const pp = m.createPriorityPreprocessor({ '**/*': ['fake'] }, {}, null, simpleFakeInstantiatePlugin)263 const file = { originalPath: '/some/CAM_PHOTO.JPG', path: 'path' }264 await pp(file)265 expect(fakePreprocessor).not.to.have.been.called266 expect(file.content).to.be.an.instanceof(Buffer)267 })268 it('should merge lists of preprocessors using default priority', async () => {269 const callOrder = []270 const fakes = {271 fakeA: sinon.spy((content, file, done) => {272 callOrder.push('a')273 done(null, content)274 }),275 fakeB: sinon.spy((content, file, done) => {276 callOrder.push('b')277 done(null, content)278 }),279 fakeC: sinon.spy((content, file, done) => {280 callOrder.push('c')281 done(null, content)282 }),283 fakeD: sinon.spy((content, file, done) => {284 callOrder.push('d')285 done(null, content)286 })287 }288 function fakeInstantiatePlugin (kind, name) {289 return fakes[name]290 }291 const pp = m.createPriorityPreprocessor({292 '/*/a.js': ['fakeA', 'fakeB'],293 '/some/*': ['fakeB', 'fakeC'],294 '/some/a.js': ['fakeD']295 }, {}, null, fakeInstantiatePlugin)296 const file = { originalPath: '/some/a.js', path: 'path' }297 await pp(file)298 expect(fakes.fakeA).to.have.been.called299 expect(fakes.fakeB).to.have.been.called300 expect(fakes.fakeC).to.have.been.called301 expect(fakes.fakeD).to.have.been.called302 expect(callOrder).to.eql(['a', 'b', 'c', 'd'])303 })304 it('should merge lists of preprocessors obeying priority', async () => {305 const callOrder = []306 const fakes = {307 fakeA: sinon.spy((content, file, done) => {308 callOrder.push('a')309 done(null, content)310 }),311 fakeB: sinon.spy((content, file, done) => {312 callOrder.push('b')313 done(null, content)314 }),315 fakeC: sinon.spy((content, file, done) => {316 callOrder.push('c')317 done(null, content)318 }),319 fakeD: sinon.spy((content, file, done) => {320 callOrder.push('d')321 done(null, content)322 })323 }324 function fakeInstantiatePlugin (kind, name) {325 return fakes[name]326 }327 const priority = { fakeA: -1, fakeB: 1, fakeD: 100 }328 const pp = m.createPriorityPreprocessor({329 '/*/a.js': ['fakeA', 'fakeB'],330 '/some/*': ['fakeB', 'fakeC'],331 '/some/a.js': ['fakeD']332 }, priority, null, fakeInstantiatePlugin)333 const file = { originalPath: '/some/a.js', path: 'path' }334 await pp(file)335 expect(fakes.fakeA).to.have.been.called336 expect(fakes.fakeB).to.have.been.called337 expect(fakes.fakeC).to.have.been.called338 expect(fakes.fakeD).to.have.been.called339 expect(callOrder).to.eql(['d', 'b', 'c', 'a'])340 })...

Full Screen

Full Screen

preprocessor.js

Source:preprocessor.js Github

copy

Full Screen

...113// Deprecated API114function createPreprocessor (preprocessors, basePath, injector) {115 console.log('Deprecated private createPreprocessor() API')116 const preprocessorPriority = injector.get('config.preprocessor_priority')117 return createPriorityPreprocessor(preprocessors, preprocessorPriority, basePath, injector)118}119createPreprocessor.$inject = ['config.preprocessors', 'config.basePath', 'injector']120exports.createPreprocessor = createPreprocessor121createPriorityPreprocessor.$inject = ['config.preprocessors', 'config.preprocessor_priority', 'config.basePath', 'injector']...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = function(config) {2 config.set({3 preprocessors: {4 },5 priorityPreprocessor: {6 }7 });8};9module.exports = function(config) {10 config.set({11 preprocessors: {12 },13 priorityPreprocessor: {14 }15 });16};17module.exports = function(config) {18 config.set({19 preprocessors: {20 },21 priorityPreprocessor: {22 }23 });24};25module.exports = function(config) {26 config.set({27 preprocessors: {28 },29 priorityPreprocessor: {30 }31 });32};33module.exports = function(config) {34 config.set({35 preprocessors: {

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = function(config) {2 config.set({3 preprocessors: {4 },5 priorityPreprocessor: {6 { pattern: 'test.js', priority: 1 },7 { pattern: 'test2.js', priority: 2 }8 }9 });10};11describe('Test', function() {12 it('should pass', function() {13 expect(true).toBe(true);14 });15});16describe('Test', function() {17 it('should pass', function() {18 expect(true).toBe(true);19 });20});21describe('Test', function() {22 it('should pass', function() {23 expect(true).toBe(true);24 });25});

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var createPriorityPreprocessor = function (logger, basePath, config) {3 var log = logger.create('preprocessor.priority');4 return function (content, file, done) {5 var filePath = path.resolve(basePath, file.originalPath);6 log.debug('Processing "%s".', filePath);7 var result = content.replace(/@priority/g, config.priority);8 done(result);9 };10};11createPriorityPreprocessor.$inject = ['logger', 'config.basePath', 'config.priorityPreprocessor'];12module.exports = {13};14module.exports = function (config) {15 config.set({16 preprocessors: {17 },18 priorityPreprocessor: {19 }20 });21};22describe('Priority Preprocessor', function () {23 it('@priority', function () {24 });25});26describe('Priority Preprocessor', function () {27 it('@priority', function () {28 });29 it('@priority', function () {30 });31});32describe('Priority Preprocessor', function () {33 it('@priority', function () {34 });35 it('@priority', function () {36 });37 it('@priority', function () {38 });39});40describe('Priority Preprocessor', function () {

Full Screen

Using AI Code Generation

copy

Full Screen

1var createPriorityPreprocessor = require("karma/lib/preprocessor").createPriorityPreprocessor;2var path = require("path");3var preprocessor = function(content, file, done) {4 done(content);5};6var preprocessors = {7 "test.js": [createPriorityPreprocessor("preprocessor", preprocessor)]8};9var config = function(config) {10 config.set({11 });12};13module.exports = config;14module.exports = function(config) {15 config.set({16 });17};

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = function(config) {2 config.set({3 preprocessors: {4 },5 priorityPreprocessor: {6 pattern: /(\d+)-(.*)\.js$/,7 }8 });9};10module.exports = function(config) {11 config.set({12 preprocessors: {13 },14 priorityPreprocessor: {15 pattern: /(\d+)-(.*)\.js$/,16 }17 });18};19module.exports = function(config) {20 config.set({21 preprocessors: {22 },23 priorityPreprocessor: {24 pattern: /(\d+)-(.*)\.js$/,25 }26 });27};28module.exports = function(config) {29 config.set({30 preprocessors: {31 },32 priorityPreprocessor: {33 pattern: /(\d+)-(.*)\.js$/,34 }35 });36};37module.exports = function(config) {38 config.set({39 preprocessors: {40 },41 priorityPreprocessor: {42 pattern: /(\d+)-(.*)\.js$/,

Full Screen

Using AI Code Generation

copy

Full Screen

1var createPriorityPreprocessor = require('karma').config.createPriorityPreprocessor;2var preprocessors = module.exports = function(config) {3 return {4 };5};6preprocessors.$inject = ['config'];7module.exports = {8 'preprocessor:customPreprocessor1': ['factory', createPriorityPreprocessor(preprocessors, 'customPreprocessor1')],9 'preprocessor:customPreprocessor2': ['factory', createPriorityPreprocessor(preprocessors, 'customPreprocessor2')]10};11module.exports = function(config) {12 config.set({13 preprocessors: {14 },15 customPreprocessor1: {16 },17 customPreprocessor2: {18 }19 });20};21module.exports = function(config) {22 config.set({23 });24};25module.exports = function(config) {26 config.set({27 });28};

Full Screen

Using AI Code Generation

copy

Full Screen

1var preprocessor = function(content, file, done) {2 var priority = 1;3 priority = parseInt(p1, 10);4 return '';5 });6 done(null, result, priority);7};8preprocessor.$inject = ['args', 'config', 'logger', 'helper'];9module.exports = {10};11module.exports = function(config) {12 config.set({13 preprocessors: {14 }15 });16};17describe('test', function() {18 it('should have priority 2', function() {19 });20});21describe('test2', function() {22 it('should have priority 1', function() {23 });24});25describe('test3', function() {26 it('should have priority 3', function() {27 });28});29module.exports = function(config) {30 config.set({31 preprocessors: {32 },33 priorityPreprocessor: {34 priority: function(a, b) {35 return a - b;36 }37 }38 });39};40describe('test', function() {41 it('should have priority 2', function() {42 });43});44describe('test2', function() {45 it('should have priority 1', function() {46 });47});48describe('test3', function() {49 it('should have priority 3', function() {50 });51});52module.exports = function(config) {53 config.set({54 preprocessors: {55 },56 priorityPreprocessor: {57 priority: function(a, b) {58 return a - b;59 },60 }61 });62};63describe('test', function

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = function(config) {2 config.set({3 preprocessors: {4 },5 createPriorityPreprocessor: {6 }7 });8};

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 Karma 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