How to use buildSource method in ava

Best JavaScript code snippet using ava

gulpfile.js

Source:gulpfile.js Github

copy

Full Screen

...25/**26 * Compile the source code into the distribution directory27 * @param {Boolean} keepSources Include the TypeScript SourceMaps28 */29function buildSource(keepSources, minifySources = false, output = null) {30 return () => {31 var stream = gulp.src(SOURCE + GLOB);32 if (keepSources) stream = stream.pipe(sm.init())33 stream = stream.pipe(ts.createProject("tsconfig.json")())34 if (keepSources) stream = stream.pipe(sm.write())35 if (minifySources) stream = stream.pipe(minify({36 ext: { min: '.js' },37 mangle: false,38 noSource: true39 }));40 else stream = stream.pipe(tabify(4, false));41 return stream.pipe(gulp.dest((output || DIST) + SOURCE));42 }43}44exports.step_buildSourceDev = buildSource(true);45exports.step_buildSource = buildSource(false);46exports.step_buildSourceMin = buildSource(false, true);47/**48 * Builds the module manifest based on the package, sources, and css.49 */50function buildManifest(output = null) {51 const files = []; // Collector for all the file paths52 return (cb) => gulp.src(PACKAGE.main) // collect the source files53 .pipe(rename({ extname: '.js' })) // rename their extensions to `.js`54 .pipe(gulp.src(CSS + GLOB)) // grab all the CSS files55 .on('data', file => files.push(path.relative(file.cwd, file.path))) // Collect all the file paths56 .on('end', () => { // output the filepaths to the module.json57 if (files.length == 0)58 throw Error('No files found in ' + SOURCE + GLOB + " or " + CSS + GLOB);59 const js = files.filter(e => e.endsWith('js')); // split the CSS and JS files60 const css = files.filter(e => e.endsWith('css'));61 fs.readFile('module.json', (err, data) => {62 const module = data.toString() // Inject the data into the module.json63 .replaceAll('{{name}}', PACKAGE.name)64 .replaceAll('{{title}}', PACKAGE.title)65 .replaceAll('{{version}}', PACKAGE.version)66 .replaceAll('{{description}}', PACKAGE.description)67 .replace('"{{sources}}"', stringify(js, null, '\t').replaceAll('\n', '\n\t'))68 .replace('"{{css}}"', stringify(css, null, '\t').replaceAll('\n', '\n\t'));69 fs.writeFile((output || DIST) + 'module.json', module, cb); // save the module to the distribution directory70 });71 });72}73exports.step_buildManifest = buildManifest();74function outputLanguages(output = null) { return () => gulp.src(LANG + GLOB).pipe(gulp.dest((output || DIST) + LANG)); }75function outputTemplates(output = null) { return () => gulp.src(TEMPLATES + GLOB).pipe(gulp.dest((output || DIST) + TEMPLATES)); }76function outputStylesCSS(output = null) { return () => gulp.src(CSS + GLOB).pipe(gulp.dest((output || DIST) + CSS)); }77function outputMetaFiles(output = null) { return () => gulp.src(['LICENSE', 'README.md', 'CHANGELOG.md']).pipe(gulp.dest((output || DIST))); }78/**79 * Copy files to module named directory and then compress that folder into a zip80 */81function compressDistribution() {82 return gulp.series(83 // Copy files to folder with module's name84 () => gulp.src(DIST + GLOB)85 .pipe(gulp.dest(DIST + `${PACKAGE.name}/${PACKAGE.name}`))86 // Compress the new folder into a ZIP and save it to the `bundle` folder87 , () => gulp.src(DIST + PACKAGE.name + '/' + GLOB)88 .pipe(zip(PACKAGE.name + '.zip'))89 .pipe(gulp.dest(BUNDLE))90 // Copy the module.json to the bundle directory91 , () => gulp.src(DIST + '/module.json')92 .pipe(gulp.dest(BUNDLE))93 // Cleanup by deleting the intermediate module named folder94 , pdel(DIST + PACKAGE.name)95 );96}97exports.step_compressDistribution = compressDistribution();98/**99 * Simple clean command100 */101exports.clean = pdel([DIST, BUNDLE]);102exports.devClean = pdel([DEV_DIST()]);103/**104 * Default Build operation105 */106exports.default = gulp.series(107 pdel([DIST])108 , gulp.parallel(109 buildSource(true, false)110 , buildManifest()111 , outputLanguages()112 , outputTemplates()113 , outputStylesCSS()114 , outputMetaFiles()115 )116);117/**118 * Extends the default build task by copying the result to the Development Environment119 */120exports.dev = gulp.series(121 pdel([DEV_DIST() + GLOB], { force: true }),122 gulp.parallel(123 buildSource(true, false, DEV_DIST())124 , buildManifest(DEV_DIST())125 , outputLanguages(DEV_DIST())126 , outputTemplates(DEV_DIST())127 , outputStylesCSS(DEV_DIST())128 , outputMetaFiles(DEV_DIST())129 )130);131/**132 * Performs a default build and then zips the result into a bundle133 */134exports.zip = gulp.series(135 pdel([DIST])136 , gulp.parallel(137 buildSource(false, false)138 , buildManifest()139 , outputLanguages()140 , outputTemplates()141 , outputStylesCSS()142 , outputMetaFiles()143 )144 , compressDistribution()145 , pdel([DIST])146);147/**148 * Sets up a file watch on the project to detect any file changes and automatically rebuild those components.149 */150exports.watch = function () {151 exports.default();152 gulp.watch(SOURCE + GLOB, gulp.series(pdel(DIST + SOURCE), buildSource(true, false)));153 gulp.watch([CSS + GLOB, 'module.json', 'package.json'], buildManifest());154 gulp.watch(LANG + GLOB, gulp.series(pdel(DIST + LANG), outputLanguages()));155 gulp.watch(TEMPLATES + GLOB, gulp.series(pdel(DIST + TEMPLATES), outputTemplates()));156 gulp.watch(CSS + GLOB, gulp.series(pdel(DIST + CSS), outputStylesCSS()));157 gulp.watch(['LICENSE', 'README.md', 'CHANGELOG.md'], outputMetaFiles());158}159/**160 * Sets up a file watch on the project to detect any file changes and automatically rebuild those components, and then copy them to the Development Environment.161 */162exports.devWatch = function () {163 const devDist = DEV_DIST();164 exports.dev();165 gulp.watch(SOURCE + GLOB, gulp.series(plog('deleting: ' + devDist + SOURCE + GLOB), pdel(devDist + SOURCE + GLOB, { force: true }), buildSource(true, false, devDist), plog('sources done.')));166 gulp.watch([CSS + GLOB, 'module.json', 'package.json'], gulp.series(reloadPackage, buildManifest(devDist), plog('manifest done.')));167 gulp.watch(LANG + GLOB, gulp.series(pdel(devDist + LANG + GLOB, { force: true }), outputLanguages(devDist), plog('langs done.')));168 gulp.watch(TEMPLATES + GLOB, gulp.series(pdel(devDist + TEMPLATES + GLOB, { force: true }), outputTemplates(devDist), plog('templates done.')));169 gulp.watch(CSS + GLOB, gulp.series(pdel(devDist + CSS + GLOB, { force: true }), outputStylesCSS(devDist), plog('css done.')));170 gulp.watch(['LICENSE', 'README.md', 'CHANGELOG.md'], gulp.series(outputMetaFiles(devDist), plog('metas done.')));...

Full Screen

Full Screen

StateWrapperView.spec.js

Source:StateWrapperView.spec.js Github

copy

Full Screen

1import sinon from 'sinon';2import chai from 'chai';3import sinonChai from 'sinon-chai';4import { stateNames } from '../constants/stateNames.js';5chai.use(sinonChai);6const { expect } = chai;7const win = global.window;8const HTMLElement = global.HTMLElement;9const Document = global.Document;10const customElements = global.customElements;11describe('stringToMethod', () => {12 let stringToMethod;13 beforeEach(async () => {14 global.window = {};15 global.HTMLElement = class {};16 global.Document = class {};17 global.customElements = {};18 ({ stringToMethod } = await import('./StateWrapperView.js'));19 });20 afterEach(() => {21 global.window = win;22 global.HTMLElement = HTMLElement;23 global.Document = Document;24 global.customElements = customElements;25 stringToMethod = null;26 });27 it('Should return the method of an element given its name', () => {28 const result = 'some str';29 const element = {30 add () { return result; }31 };32 expect(stringToMethod(element, 'add')()).to.equal(result);33 });34 it('Should return undefined if there is no element', () => {35 expect(stringToMethod(null, 'add')).to.be.undefined;36 });37 it('Should return undefined if the name is not an element\'s method', () => {38 const result = 'some str';39 const element = {40 add () { return result; }41 };42 expect(stringToMethod(element, 'multiply')).to.be.undefined;43 });44 it('Should return undefined if the name is an element\'s ' +45 'property but not a method', () => {46 const result = 'some str';47 const element = {48 add () { return result; },49 extra: 5050 };51 expect(stringToMethod(element, 'extra')).to.be.undefined;52 });53 it('Should bind the element to its method', () => {54 const element = {55 add () { return this.extra; },56 extra: 5057 };58 expect(stringToMethod(element, 'add')()).to.equal(50);59 });60});61describe('prepareView', () => {62 let prepareView;63 beforeEach(async () => {64 global.window = {};65 global.HTMLElement = class {};66 global.Document = class {};67 global.customElements = {};68 ({ prepareView } = await import('./StateWrapperView.js'));69 });70 afterEach(() => {71 global.window = win;72 global.HTMLElement = HTMLElement;73 global.Document = Document;74 global.customElements = customElements;75 prepareView = null;76 });77 it('Should send a function as the view\'s action', () => {78 const state = {79 name: stateNames.RECOVERY,80 action: 'buildSource',81 view: sinon.spy()82 };83 const wrapped = {84 buildInput: sinon.spy(),85 buildSource: sinon.spy()86 };87 const recovery = sinon.spy();88 prepareView(state, wrapped, recovery);89 const { args } = state.view.firstCall;90 expect(state.view).to.have.been.calledOnce;91 expect(args[0].wrapped).to.equal(wrapped);92 expect(args[0].view).to.be.undefined;93 args[0].action();94 expect(recovery).to.have.been.calledOnce;95 });96 it('Should send an element\'s method as the view\'s action', () => {97 const state = {98 name: stateNames.RECOVERY,99 action: 'buildSource',100 view: sinon.spy()101 };102 const wrapped = {103 buildInput: sinon.spy(),104 buildSource: sinon.spy()105 };106 prepareView(state, wrapped, 'buildInput');107 const { args } = state.view.firstCall;108 expect(state.view).to.have.been.calledOnce;109 expect(args[0].wrapped).to.equal(wrapped);110 expect(args[0].view).to.be.undefined;111 args[0].action();112 expect(wrapped.buildInput).to.have.been.calledOnce;113 expect(wrapped.buildInput.firstCall.thisValue).to.equal(wrapped);114 });115 it('Should send the state\'s default action ' +116 'as the view\'s action', () => {117 const state = {118 name: stateNames.RECOVERY,119 action: 'buildSource',120 view: sinon.spy()121 };122 const wrapped = {123 buildInput: sinon.spy(),124 buildSource: sinon.spy()125 };126 prepareView(state, wrapped);127 const { args } = state.view.firstCall;128 expect(state.view).to.have.been.calledOnce;129 expect(args[0].wrapped).to.equal(wrapped);130 expect(args[0].view).to.be.undefined;131 args[0].action();132 expect(wrapped.buildSource).to.have.been.calledOnce;133 expect(wrapped.buildSource.firstCall.thisValue).to.equal(wrapped);134 });135 it('Should not send an action to the view ' +136 'if the state is not recovery', () => {137 const state = {138 action: 'buildSource',139 view: sinon.spy()140 };141 const wrapped = {142 buildInput: sinon.spy(),143 buildSource: sinon.spy()144 };145 const recovery = sinon.spy();146 prepareView(state, wrapped, recovery);147 const { args } = state.view.firstCall;148 expect(state.view).to.have.been.calledOnce;149 expect(args[0].wrapped).to.equal(wrapped);150 expect(args[0].view).to.be.undefined;151 expect(args[0].action).to.be.undefined;152 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2test('my passing test', t => {3 t.pass();4});5const test = require('ava');6test('my passing test', t => {7 t.pass();8});9const test = require('ava');10test('my passing test', t => {11 t.pass();12});13const test = require('ava');14test('my passing test', t => {15 t.pass();16});17const test = require('ava');18test('my passing test', t => {19 t.pass();20});21const test = require('ava');22test('my passing test', t => {23 t.pass();24});25const test = require('ava');26test('my passing test', t => {27 t.pass();28});29const test = require('ava');30test('my passing test', t => {31 t.pass();32});33Default: `process.cwd()`

Full Screen

Using AI Code Generation

copy

Full Screen

1var availity = require('availity-angular');2var fs = require('fs');3var path = require('path');4var src = path.join(__dirname, 'src');5var dist = path.join(__dirname, 'dist');6var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava')2const buildSource = require('ava/lib/worker/build-source')3const source = buildSource(__filename)4console.log(source)5const test = require('ava')6const buildSourceSync = require('ava/lib/worker/build-source-sync')7const source = buildSourceSync(__filename)8console.log(source)9const test = require('ava')10const buildSourceString = require('ava/lib/worker/build-source-string')11const source = buildSourceString(__filename)12console.log(source)13const test = require('ava')14const buildSourceStringSync = require('ava/lib/worker/build-source-string-sync')15const source = buildSourceStringSync(__filename)16console.log(source)17const test = require('ava')18const buildSourceStringSync = require('ava/lib/worker/build-source-string-sync')19const source = buildSourceStringSync(__filename)20console.log(source)21const test = require('ava')22const {cleanCache} = require('ava/lib/worker/cache')23cleanCache()

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var path = require('path');3var buildSource = require('json-schema-to-typescript').buildSource;4var schema = require('./schema.json');5buildSource(schema).then(ts => {6 fs.writeFileSync(path.join(__dirname, 'schema.d.ts'), ts);7});8### `buildSource(schema: JSONSchema, options?: Options): Promise<string>`9### `buildFile(schemaPath: string, options?: Options): Promise<string>`10### `build(schema: JSONSchema, options?: Options): Promise<SchemaResult>`11- `cwdRelativeReplaceRegExFlags?: string | string[] = []` - The regular expression(s) flags to replace

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const {buildSource} = require('../lib/build-source');3test('buildSource', t => {4 const source = buildSource('test.js', 'test', 'test');5 t.is(source, 'test("test", t => {test});');6});7MIT © [Rajikaimal](

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const buildSource = require('./buildSource');3const source = buildSource('./src/index.js', './src/index.test.js');4test('test', t => {5 t.pass();6});

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