Best JavaScript code snippet using playwright-internal
init.test.ts
Source:init.test.ts
1import { expect } from 'chai';2import fs from 'fs';3import yaml from 'js-yaml';4import mock_fs from 'mock-fs';5import path from 'path';6import sinon from 'sinon';7import { buildConfigFromYml, Slugs } from '../../src';8import { InitCommand } from '../../src/commands/init';9import { mockArchitectAuth } from '../utils/mocks';10describe('init', function () {11 // set to true while working on tests for easier debugging; otherwise oclif/test eats the stdout/stderr12 const print = false;13 const compose_file_name = 'init-compose.yml';14 const compose_file_path = path.join(__dirname, `../mocks/${compose_file_name}`);15 const mock_compose_contents = `16version: "3.7"17services:18`;19 const mockInit = () => {20 return mockArchitectAuth21 .stub(fs, 'writeFileSync', sinon.stub().returns(undefined))22 .stdout({ print })23 .stderr({ print })24 }25 mockInit()26 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])27 .it('converts a docker-compose file to an architect component file', ctx => {28 const writeFileSync = fs.writeFileSync as sinon.SinonStub;29 expect(writeFileSync.called).to.be.true;30 expect(ctx.stdout).to.contain(`Converted ${compose_file_name} and wrote Architect component config to architect.yml`);31 expect(ctx.stdout).to.contain('The component config may be incomplete and should be checked for consistency with the context of your application. Helpful reference docs can be found at https://docs.architect.io/components/architect-yml.');32 });33 mockInit()34 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component', '-o', 'test-directory/architect.yml'])35 .it('converts a docker-compose file to an architect component file and writes the file to a specified output', ctx => {36 const writeFileSync = fs.writeFileSync as sinon.SinonStub;37 expect(writeFileSync.called).to.be.true;38 expect(writeFileSync.args[0][0]).eq('test-directory/architect.yml');39 expect(ctx.stdout).to.contain(`Converted ${compose_file_name} and wrote Architect component config to test-directory/architect.yml`);40 expect(ctx.stdout).to.contain('The component config may be incomplete and should be checked for consistency with the context of your application. Helpful reference docs can be found at https://docs.architect.io/components/architect-yml.');41 });42 mockInit()43 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])44 .it('names the component based on the input args', ctx => {45 const writeFileSync = fs.writeFileSync as sinon.SinonStub;46 expect(writeFileSync.called).to.be.true;47 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);48 expect(component_config.name).eq(`test-component`);49 });50 mockInit()51 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])52 .it('converts all services from the docker compose file to architect services', ctx => {53 const writeFileSync = fs.writeFileSync as sinon.SinonStub;54 expect(writeFileSync.called).to.be.true;55 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);56 expect(Object.keys(component_config.services || {})).deep.equal(['elasticsearch', 'logstash', 'kibana']);57 });58 mockInit()59 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])60 .it('adds environment variables to each service', ctx => {61 const writeFileSync = fs.writeFileSync as sinon.SinonStub;62 expect(writeFileSync.called).to.be.true;63 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);64 expect(component_config.services['elasticsearch'].environment['ES_JAVA_OPTS']).eq('-Xmx256m -Xms256m');65 expect(component_config.services['elasticsearch'].environment['ELASTIC_PASSWORD']).eq('changeme');66 expect(component_config.services['elasticsearch'].environment['DISCOVERY_TYPE']).eq('single-node');67 expect(component_config.services['elasticsearch'].environment['TEST_NUMBER']).eq('3000');68 expect(component_config.services['logstash'].environment['LS_JAVA_OPTS']).eq('-Xmx256m -Xms256m');69 expect(component_config.services['logstash'].environment['ELASTICSEARCH_URL']).eq('${{ services.elasticsearch.interfaces.main.url }}');70 expect(component_config.services['logstash'].environment['KIBANA_URL']).eq('${{ services.kibana.interfaces.main.url }}');71 expect(component_config.services['kibana'].environment['ELASTICSEARCH_URL']).eq('${{ services.elasticsearch.interfaces.main.url }}');72 });73 mockInit()74 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])75 .it('converts environment variables from compose listed as an array', ctx => {76 const writeFileSync = fs.writeFileSync as sinon.SinonStub;77 expect(writeFileSync.called).to.be.true;78 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);79 expect(component_config.services['kibana'].environment['DB_TYPE']).eq('postgres');80 expect(component_config.services['kibana'].environment['DB_NAME']).eq('gitea');81 expect(component_config.services['kibana'].environment['DB_USER']).eq('gitea');82 expect(component_config.services['kibana'].environment['DB_PASSWD']).eq('gitea');83 });84 mockInit()85 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])86 .it(`warns the user if a listed environment variable couldn't be converted`, ctx => {87 const writeFileSync = fs.writeFileSync as sinon.SinonStub;88 expect(writeFileSync.called).to.be.true;89 expect(ctx.stdout).to.contain('Could not convert environment variable DB_HOST');90 });91 mockInit()92 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])93 .it('adds command to logstash service', ctx => {94 const writeFileSync = fs.writeFileSync as sinon.SinonStub;95 expect(writeFileSync.called).to.be.true;96 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);97 expect(component_config.services['logstash'].command).deep.eq(['npm', 'run', 'start']);98 });99 mockInit()100 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])101 .it('adds entrypoint to logstash service', ctx => {102 const writeFileSync = fs.writeFileSync as sinon.SinonStub;103 expect(writeFileSync.called).to.be.true;104 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);105 expect(component_config.services['logstash'].entrypoint).deep.eq(['entrypoint.sh']);106 });107 mockInit()108 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])109 .it('adds image to kibana service', ctx => {110 const writeFileSync = fs.writeFileSync as sinon.SinonStub;111 expect(writeFileSync.called).to.be.true;112 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);113 expect(component_config.services['kibana'].image).eq('docker.elastic.co/kibana/kibana:7.8.0');114 });115 mockInit()116 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])117 .it('adds build context and args to elasticsearch service', ctx => {118 const writeFileSync = fs.writeFileSync as sinon.SinonStub;119 expect(writeFileSync.called).to.be.true;120 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);121 expect(component_config.services['elasticsearch'].build!.args!['ELK_VERSION']).eq('$ELK_VERSION');122 expect(component_config.services['elasticsearch'].build!.context).eq('elasticsearch/');123 expect(component_config.services['elasticsearch'].build!.dockerfile).eq('Dockerfile.elasticsearch');124 });125 mockInit()126 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])127 .it('adds ports of various docker-compose types to kibana service config', ctx => {128 const writeFileSync = fs.writeFileSync as sinon.SinonStub;129 expect(writeFileSync.called).to.be.true;130 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);131 expect(component_config.services['kibana'].interfaces['main'].port).eq(5601);132 expect(component_config.services['kibana'].interfaces['main2'].port).eq(5000);133 expect(component_config.services['kibana'].interfaces['main2'].protocol).eq('udp');134 expect(component_config.services['kibana'].interfaces['main3'].port).eq(8001);135 expect(component_config.services['kibana'].interfaces['main4'].port).eq(3000);136 expect(component_config.services['kibana'].interfaces['main5'].port).eq(4000);137 expect(component_config.services['kibana'].interfaces['main10'].port).eq(4005);138 expect(component_config.services['kibana'].interfaces['main11'].port).eq(1240);139 expect(component_config.services['kibana'].interfaces['main12'].port).eq(8080);140 expect(component_config.services['kibana'].interfaces['main13'].port).eq(8081);141 expect(component_config.services['kibana'].interfaces['main14'].port).eq(5000);142 expect(component_config.services['kibana'].interfaces['main24'].port).eq(5010);143 expect(component_config.services['kibana'].interfaces['main25'].port).eq(4444);144 expect(component_config.services['kibana'].interfaces['main25'].protocol).eq('tcp');145 expect(component_config.services['kibana'].interfaces['main26'].port).eq(4445);146 expect(component_config.services['kibana'].interfaces['main26'].protocol).eq('udp');147 });148 mockInit()149 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])150 .it('adds ports to service component config', ctx => {151 const writeFileSync = fs.writeFileSync as sinon.SinonStub;152 expect(writeFileSync.called).to.be.true;153 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);154 expect(component_config.services['elasticsearch'].interfaces['main'].port).eq(9200);155 expect(component_config.services['elasticsearch'].interfaces['main2'].port).eq(9300);156 });157 mockInit()158 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])159 .it('adds ports to logstash service config', ctx => {160 const writeFileSync = fs.writeFileSync as sinon.SinonStub;161 expect(writeFileSync.called).to.be.true;162 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);163 expect(component_config.services['logstash'].interfaces['main'].port).eq(5000);164 expect(component_config.services['logstash'].interfaces['main'].protocol).eq('tcp');165 expect(component_config.services['logstash'].interfaces['main2'].port).eq(5000);166 expect(component_config.services['logstash'].interfaces['main2'].protocol).eq('udp');167 expect(component_config.services['logstash'].interfaces['main3'].port).eq(9600);168 });169 mockInit()170 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])171 .it('adds debug and regular volumes to elasticsearch service config', ctx => {172 const writeFileSync = fs.writeFileSync as sinon.SinonStub;173 expect(writeFileSync.called).to.be.true;174 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);175 const component_object: any = yaml.load(writeFileSync.args[0][1]);176 expect(component_config.services['elasticsearch'].volumes['volume2'].mount_path).eq('/usr/share/elasticsearch/data');177 expect(component_object.services['elasticsearch'].debug.volumes['volume'].mount_path).eq('/usr/share/elasticsearch/config/elasticsearch.yml');178 expect(component_object.services['elasticsearch'].debug.volumes['volume'].host_path).eq('./elasticsearch/config/elasticsearch.yml');179 expect(component_object.services['elasticsearch'].debug.volumes['volume'].readonly).eq(true);180 });181 mockInit()182 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])183 .it('adds debug volumes to logstash service config', ctx => {184 const writeFileSync = fs.writeFileSync as sinon.SinonStub;185 expect(writeFileSync.called).to.be.true;186 const component_object: any = yaml.load(writeFileSync.args[0][1]);187 expect(component_object.services['logstash'].debug.volumes['volume'].mount_path).eq('/usr/share/logstash/config/logstash.yml');188 expect(component_object.services['logstash'].debug.volumes['volume'].host_path).eq('./logstash/config/logstash.yml');189 expect(component_object.services['logstash'].debug.volumes['volume'].readonly).eq(true);190 expect(component_object.services['logstash'].debug.volumes['volume2'].mount_path).eq('/usr/share/logstash/pipeline');191 expect(component_object.services['logstash'].debug.volumes['volume2'].host_path).eq('./logstash/pipeline');192 expect(component_object.services['logstash'].debug.volumes['volume2'].readonly).eq(true);193 });194 mockInit()195 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])196 .it('adds debug and regular volumes to kibana service config', ctx => {197 const writeFileSync = fs.writeFileSync as sinon.SinonStub;198 expect(writeFileSync.called).to.be.true;199 const component_config = buildConfigFromYml(writeFileSync.args[0][1]);200 const component_object: any = yaml.load(writeFileSync.args[0][1]);201 expect(component_object.services['kibana'].debug.volumes['volume'].mount_path).eq('/usr/share/kibana/config/kibana.yml');202 expect(component_object.services['kibana'].debug.volumes['volume'].host_path).eq('./kibana/config/kibana.yml');203 expect(component_object.services['kibana'].debug.volumes['volume'].readonly).eq(true);204 expect(component_config.services['kibana'].volumes['volume2'].mount_path).eq('/var/lib/mysql');205 expect(component_config.services['kibana'].volumes['volume2'].host_path).is.undefined;206 expect(component_object.services['kibana'].debug.volumes['volume3'].mount_path).eq('/var/lib/mysql');207 expect(component_object.services['kibana'].debug.volumes['volume3'].host_path).eq('/opt/data');208 expect(component_object.services['kibana'].debug.volumes['volume4'].mount_path).eq('/tmp/cache');209 expect(component_object.services['kibana'].debug.volumes['volume4'].host_path).eq('./cache');210 expect(component_object.services['kibana'].debug.volumes['volume5'].mount_path).eq('/etc/configs/');211 expect(component_object.services['kibana'].debug.volumes['volume5'].host_path).eq('~/configs');212 expect(component_object.services['kibana'].debug.volumes['volume5'].readonly).eq(true);213 });214 mockInit()215 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])216 .it('adds context targets to compose where appropriate', ctx => {217 const writeFileSync = fs.writeFileSync as sinon.SinonStub;218 expect(writeFileSync.called).to.be.true;219 const component_object: any = yaml.load(writeFileSync.args[0][1]);220 expect(component_object.services['elasticsearch'].build.target).eq('production');221 expect(component_object.services['logstash'].build.target).eq('build');222 expect(component_object.services['kibana'].build?.target).undefined;223 });224 mockInit()225 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])226 .it('prints a warning if a field from the docker compose cannot be converted', ctx => {227 const writeFileSync = fs.writeFileSync as sinon.SinonStub;228 expect(writeFileSync.called).to.be.true;229 expect(ctx.stdout).to.contain(`Could not convert elasticsearch property "networks"`);230 expect(ctx.stdout).to.contain(`Could not convert logstash property "networks"`);231 expect(ctx.stdout).to.contain(`Could not convert kibana property "networks"`);232 });233 it('finds a compose file in the current directory if one was unspecified', async () => {234 mock_fs({235 './docker-compose.yml': mock_compose_contents,236 });237 const getComposeFromPath = InitCommand.prototype.getComposeFromPath;238 const compose_path = await getComposeFromPath({});239 expect(compose_path).eq('docker-compose.yml');240 });241 it('finds and returns a valid compose file path if it was specified', async () => {242 mock_fs({243 '/stack/docker-compose.yml': mock_compose_contents,244 });245 const getComposeFromPath = InitCommand.prototype.getComposeFromPath;246 const compose_path = await getComposeFromPath({ 'from-compose': '/stack/docker-compose.yml' });247 expect(compose_path).eq(path.join(path.parse(process.cwd()).root, 'stack', 'docker-compose.yml'));248 });249 it(`returns an error if the compose file was specified, but it doesn't exist`, async () => {250 mock_fs({251 '/stack/docker-compose.yml': mock_compose_contents,252 });253 const getComposeFromPath = InitCommand.prototype.getComposeFromPath;254 try {255 await getComposeFromPath({ 'from-compose': '/stack/bad-path/docker-compose.yml' });256 } catch (err: any) {257 expect(err.message).eq(`The Docker Compose file /stack/bad-path/docker-compose.yml couldn't be found.`);258 }259 });260 mockInit()261 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])262 .it('converts a healthcheck with cmd-shell to a liveness probe', ctx => {263 const writeFileSync = fs.writeFileSync as sinon.SinonStub;264 expect(writeFileSync.called).to.be.true;265 const component_object: any = yaml.load(writeFileSync.args[0][1]);266 expect(component_object.services['elasticsearch'].liveness_probe).deep.eq({267 command: ["/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P example_123 -Q 'SELECT 1'"],268 interval: '10s',269 timeout: '3s',270 failure_threshold: 10,271 initial_delay: '10s'272 });273 });274 mockInit()275 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])276 .it('converts a healthcheck with cmd to a liveness probe', ctx => {277 const writeFileSync = fs.writeFileSync as sinon.SinonStub;278 expect(writeFileSync.called).to.be.true;279 const component_object: any = yaml.load(writeFileSync.args[0][1]);280 expect(component_object.services['logstash'].liveness_probe).deep.eq({281 command: ["mysqladmin", "ping", "-h", "127.0.0.1", "--silent"],282 interval: '3s',283 failure_threshold: 5,284 initial_delay: '30s'285 });286 });287 mockInit()288 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])289 .it('converts a healthcheck string to a liveness probe', ctx => {290 const writeFileSync = fs.writeFileSync as sinon.SinonStub;291 expect(writeFileSync.called).to.be.true;292 const component_object: any = yaml.load(writeFileSync.args[0][1]);293 expect(component_object.services['kibana'].liveness_probe).deep.eq({294 command: 'curl google.com',295 });296 });297 mockInit()298 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])299 .it('converts a container name to a reserved name', ctx => {300 const writeFileSync = fs.writeFileSync as sinon.SinonStub;301 expect(writeFileSync.called).to.be.true;302 const component_object: any = yaml.load(writeFileSync.args[0][1]);303 expect(component_object.services['logstash'].reserved_name).eq('logstash-service');304 });305 mockInit()306 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])307 .it('adds an interface for each exposed port', ctx => {308 const writeFileSync = fs.writeFileSync as sinon.SinonStub;309 expect(writeFileSync.called).to.be.true;310 const component_object: any = yaml.load(writeFileSync.args[0][1]);311 expect(component_object.services['elasticsearch'].interfaces.expose.port).eq(5432);312 });313 mockInit()314 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])315 .it('adding cpu and memory resources', ctx => {316 const writeFileSync = fs.writeFileSync as sinon.SinonStub;317 expect(writeFileSync.called).to.be.true;318 const component_object: any = yaml.load(writeFileSync.args[0][1]);319 expect(component_object.services['logstash'].cpu).eq(0.25);320 expect(component_object.services['logstash'].memory).eq('1.5G');321 });322 mockInit()323 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])324 .it('converting labels in array format', ctx => {325 const writeFileSync = fs.writeFileSync as sinon.SinonStub;326 expect(writeFileSync.called).to.be.true;327 const component_object: any = yaml.load(writeFileSync.args[0][1]);328 expect(component_object.services['kibana'].labels.enable).eq('true');329 expect(component_object.services['kibana'].labels.rule).eq('test');330 });331 mockInit()332 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])333 .it('converting labels in object format', ctx => {334 const writeFileSync = fs.writeFileSync as sinon.SinonStub;335 expect(writeFileSync.called).to.be.true;336 const component_object: any = yaml.load(writeFileSync.args[0][1]);337 expect(component_object.services['logstash'].labels.ENABLE).eq('true');338 expect(component_object.services['logstash'].labels.RULE).eq('test');339 });340 mockInit()341 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])342 .it(`warns the user if a listed label couldn't be converted because it isn't split by an = sign`, ctx => {343 const writeFileSync = fs.writeFileSync as sinon.SinonStub;344 expect(writeFileSync.called).to.be.true;345 expect(ctx.stdout).to.contain('Could not convert label key_only as it is not 2 parts separated by an "=" sign');346 });347 mockInit()348 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])349 .it(`warns the user if a listed label couldn't be converted because of an invalid key`, ctx => {350 const writeFileSync = fs.writeFileSync as sinon.SinonStub;351 expect(writeFileSync.called).to.be.true;352 expect(ctx.stdout).to.contain(`Label with key rule.invalid&key could not be converted as it fails validation with regex ${Slugs.LabelKeySlugValidatorString}`);353 });354 mockInit()355 .command(['init', '--from-compose', compose_file_path, '-n', 'test-component'])356 .it(`warns the user if a listed label couldn't be converted because of an invalid value`, ctx => {357 const writeFileSync = fs.writeFileSync as sinon.SinonStub;358 expect(writeFileSync.called).to.be.true;359 expect(ctx.stdout).to.contain(`Label with value Path(\`/\`) could not be converted as it fails validation with regex ${Slugs.LabelValueSlugValidatorString}`);360 });...
add-plugin-command.spec.js
Source:add-plugin-command.spec.js
1jest.mock('../copy-plugin-to-resources');2jest.mock('request', () => ({3 get: jest.fn((url, cb) => {4 const error = url === 'https://gitlab.com/cordova-plugins/cordova-bluetoothsco/raw/master/package.json';5 cb(error, { statusCode: 200 }, url);6 }),7}));8jest.mock('fs-extra', () => {9 const os = require('os');10 const platforms = {11 win32: 'win32',12 mac: 'darwin',13 linux: 'linux'14 };15 const currentPlatform = os.platform();16 const testFiles = (currentPlatform === platforms.mac || currentPlatform === platforms.linux) ?17 [18 '~/package.json',19 'temp/package.json',20 '/temp/package.json',21 'temp/localPath/plugin.xml',22 '/temp/localPath/plugin.xml',23 'temp/plugins/fetch.json',24 `localPath/plugin.xml`,25 `/localPath/plugin.xml`,26 `~/localPath/plugin.xml`27 ]:28 [29 '~\\package.json',30 'temp\\package.json',31 '\\temp\\package.json',32 'temp\\localPath\\plugin.xml',33 '\\temp\\localPath\\plugin.xml',34 'temp\\plugins\\fetch.json',35 `localPath\\plugin.xml`,36 `\\localPath\\plugin.xml`,37 `~\\localPath\\plugin.xml`38 ];39 return {40 existsSync: (path) => testFiles.includes(path)41 ,42 mkdirpSync: jest.fn(),43 writeJSONSync: jest.fn(),44 writeFileSync: jest.fn(),45 readFileSync: () => jest.fn(),46 }47});48jest.mock('../get-plugin-name-from-xml', () => jest.fn());49jest.mock('../load-json');50const copy = require('../copy-plugin-to-resources');51const addPlugin = require('../add-plugin-command');52const getPluginNameFromXml = require('../get-plugin-name-from-xml');53const request = require('request');54const fsExtra = require('fs-extra');55const path = require('path');56const loadJson = require('../load-json');57const platforms = {58 win32: 'win32',59 mac: 'darwin',60 linux: 'linux'61};62const os = require('os');63const currentPlatform = os.platform();64const rootPathPrefix = (currentPlatform === platforms.linux || currentPlatform === platforms.mac) ? '/' : '';65test('Works', () => {66 expect(true).toBeTruthy();67});68test('Test copyPluginToResources', () => {69 copy('foo');70 expect(copy).toHaveBeenCalledWith('foo');71 copy.mockClear();72});73afterEach(() => {74 fsExtra.writeFileSync.mockClear();75 request.get.mockClear();76 copy.mockClear();77})78const projectDir = 'temp';79const expectedPkgJsonPath = path.join(projectDir, 'package.json');80describe('Add plugin from local folder', () => {81 describe('Argument starts with file:/', () => {82 const pluginName = "cordova-plugin-camera";83 const projectDir = 'temp';84 const folder = "localPath";85 const pluginPath = path.join(projectDir, folder);86 const expectedPkgJsonPath = path.join(projectDir, 'package.json');87 const expectedFetchJsonPath = path.join(projectDir, 'plugins', 'fetch.json');88 getPluginNameFromXml.mockReturnValue(pluginName);89 test('Copy has been called and Pakcage.json has been updated correctly', async () => {90 await addPlugin([91 "node",92 "monaca",93 "plugin",94 "add",95 `file:/${pluginPath}`96 ],97 projectDir98 );99 expect(copy).toHaveBeenCalledWith(projectDir, rootPathPrefix + path.normalize(pluginPath), pluginName);100 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);101 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, 'file:res/custom_plugins/' + pluginName);102 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});103 });104 test.skip('fetch.json has been updated correctly', async () => {105 await addPlugin([106 "node",107 "monaca",108 "plugin",109 "add",110 `file:/${folder}`111 ],112 projectDir113 );114 expect(fsExtra.writeFileSync.mock.calls[1][0]).toBe(expectedFetchJsonPath);115 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'source.type', 'registry');116 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'source.id', `file:/${folder}`);117 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'variables', {});118 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'isTopLevel', true);119 });120 });121 describe('Argument starts with file://', () => {122 const pluginName = "cordova-plugin-camera";123 const projectDir = 'temp';124 const folder = "localPath"125 const pluginPath = path.join(projectDir, folder);126 const expectedPkgJsonPath = path.join(projectDir, 'package.json');127 const expectedFetchJsonPath = path.join(projectDir, 'plugins', 'fetch.json');128 getPluginNameFromXml.mockReturnValue(pluginName);129 test('Copy has been called and Package.json has been updated correctly', async () => {130 await addPlugin([131 "node",132 "monaca",133 "plugin",134 "add",135 `file://${pluginPath}`136 ],137 projectDir138 );139 expect(copy).toHaveBeenCalledWith(projectDir, rootPathPrefix + pluginPath, pluginName);140 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);141 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, 'file:res/custom_plugins/' + pluginName);142 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});143 });144 test.skip('fetch.json has been updated correctly', async () => {145 await addPlugin([146 "node",147 "monaca",148 "plugin",149 "add",150 `file://${folder}`151 ],152 projectDir153 );154 expect(fsExtra.writeFileSync.mock.calls[1][0]).toBe(expectedFetchJsonPath);155 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'source.type', 'registry');156 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'source.id', `file://${folder}`);157 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'variables', {});158 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'isTopLevel', true);159 });160 });161 describe('Argument starts with file:///', () => {162 const pluginName = "cordova-plugin-camera";163 const projectDir = 'temp';164 const folder = "localPath"165 const pluginPath = path.join(projectDir, folder);166 const expectedPkgJsonPath = path.join(projectDir, 'package.json');167 const expectedFetchJsonPath = path.join(projectDir, 'plugins', 'fetch.json');168 getPluginNameFromXml.mockReturnValue(pluginName);169 test('Copy has been called and Pakcage.json has been updated correctly', async () => {170 await addPlugin([171 "node",172 "monaca",173 "plugin",174 "add",175 `file:///${pluginPath}`176 ],177 projectDir178 );179 expect(copy).toHaveBeenCalledWith(projectDir, rootPathPrefix + path.normalize(pluginPath), pluginName);180 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);181 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, 'file:res/custom_plugins/' + pluginName);182 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});183 });184 test.skip('fetch.json has been updated correctly', async () => {185 await addPlugin([186 "node",187 "monaca",188 "plugin",189 "add",190 `file://${folder}`191 ],192 projectDir193 );194 expect(fsExtra.writeFileSync.mock.calls[1][0]).toBe(expectedFetchJsonPath);195 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'source.type', 'registry');196 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'source.id', `file://${folder}`);197 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'variables', {});198 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'isTopLevel', true);199 });200 });201 describe('Argument starts with /', () => {202 const pluginName = "cordova-plugin-camera";203 const projectDir = '/temp';204 const folder = "localPath"205 const expectedPkgJsonPath = path.join(projectDir, 'package.json');206 const expectedFetchJsonPath = path.join(projectDir, 'plugins', 'fetch.json');207 getPluginNameFromXml.mockReturnValue(pluginName);208 test('Copy has been called and Package.json has been updated correctly', async () => {209 await addPlugin([210 "node",211 "monaca",212 "plugin",213 "add",214 `${projectDir}/${folder}`215 ],216 projectDir217 );218 expect(copy).toHaveBeenCalledWith(projectDir, path.normalize(`${projectDir}/${folder}`), pluginName);219 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);220 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, 'file:res/custom_plugins/' + pluginName);221 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});222 });223 test.skip('fetch.json has been updated correctly', async () => {224 await addPlugin([225 "node",226 "monaca",227 "plugin",228 "add",229 `file://${folder}`230 ],231 projectDir232 );233 expect(fsExtra.writeFileSync.mock.calls[1][0]).toBe(expectedFetchJsonPath);234 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'source.type', 'registry');235 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'source.id', `file://${folder}`);236 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'variables', {});237 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[1][1])).toHaveProperty(pluginName, 'isTopLevel', true);238 });239 });240 describe('Argument starts with ~', () => {241 const pluginName = "cordova-plugin-camera";242 const projectDir = '~';243 const folder = "localPath"244 const pluginPath = path.join(projectDir, folder);245 const expectedPkgJsonPath = path.join(projectDir, 'package.json');246 const expectedFetchJsonPath = path.join(projectDir, 'plugins', 'fetch.json');247 getPluginNameFromXml.mockReturnValue(pluginName);248 test('Copy has been called and Pakcage.json has been updated correctly', async () => {249 await addPlugin([250 "node",251 "monaca",252 "plugin",253 "add",254 `${pluginPath}`255 ],256 projectDir257 );258 expect(copy).toHaveBeenCalledWith(projectDir, path.normalize(pluginPath), pluginName);259 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);260 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, 'file:res/custom_plugins/' + pluginName);261 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});262 });263 });264});265describe('Add plugin from GitHub', () => {266 test('Default case: https://github.com/apache/cordova-plugin-camera/', async () => {267 const pluginName = "cordova-plugin-camera";268 const gitUrl = 'https://github.com/apache/cordova-plugin-camera/';269 const rawFileUrl = 'https://raw.githubusercontent.com/apache/cordova-plugin-camera/master/plugin.xml'270 const expectedDependencyValue = 'git+https://github.com/apache/cordova-plugin-camera';271 getPluginNameFromXml.mockReturnValue(pluginName);272 await addPlugin([273 "node",274 "monaca",275 "plugin",276 "add",277 gitUrl278 ],279 projectDir280 );281 expect(request.get.mock.calls[0][0]).toBe(rawFileUrl);282 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);283 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, expectedDependencyValue);284 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});285 });286 test('Specific github branch: https://github.com/apache/cordova-plugin-camera#4.1.0', async () => {287 const pluginName = "cordova-plugin-camera";288 const gitUrl = 'https://github.com/apache/cordova-plugin-camera#4.1.0';289 const rawFileUrl = 'https://raw.githubusercontent.com/apache/cordova-plugin-camera/4.1.0/plugin.xml'290 const expectedDependencyValue = 'git+https://github.com/apache/cordova-plugin-camera#4.1.0';291 getPluginNameFromXml.mockReturnValue(pluginName);292 await addPlugin([293 "node",294 "monaca",295 "plugin",296 "add",297 gitUrl298 ],299 projectDir300 );301 expect(request.get.mock.calls[0][0]).toBe(rawFileUrl);302 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);303 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, expectedDependencyValue);304 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});305 });306 test('Specific github branch with .git in the url: https://github.com/apache/cordova-plugin-camera#4.1.0',307 async () => {308 const pluginName = "cordova-plugin-camera";309 const gitUrl = 'https://github.com/apache/cordova-plugin-camera.git#4.1.0';310 const rawFileUrl = 'https://raw.githubusercontent.com/apache/cordova-plugin-camera/4.1.0/plugin.xml'311 const expectedDependencyValue = 'git+https://github.com/apache/cordova-plugin-camera.git#4.1.0';312 getPluginNameFromXml.mockReturnValue(pluginName);313 await addPlugin([314 "node",315 "monaca",316 "plugin",317 "add",318 gitUrl319 ],320 projectDir321 );322 expect(request.get.mock.calls[0][0]).toBe(rawFileUrl);323 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);324 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, expectedDependencyValue);325 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});326 });327});328describe('Add plugin from GitLab', () => {329 test('Default case: https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver', async () => {330 const pluginName = "cordova-plugin-camera";331 const gitUrl = 'https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver';332 const rawFileUrl = 'https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver/raw/master/plugin.xml'333 const expectedDependencyValue = 'git+https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver';334 getPluginNameFromXml.mockReturnValue(pluginName);335 await addPlugin([336 "node",337 "monaca",338 "plugin",339 "add",340 gitUrl341 ],342 projectDir343 );344 expect(request.get.mock.calls[0][0]).toBe(rawFileUrl);345 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);346 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, expectedDependencyValue);347 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});348 });349 test('Specific gitlab hash: https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver#cc0a604d643107f426ae35276fbe7dfaac435105', async () => {350 const pluginName = "cordova-plugin-camera";351 const gitUrl = 'https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver#cc0a604d643107f426ae35276fbe7dfaac435105';352 const rawFileUrl = 'https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver/raw/cc0a604d643107f426ae35276fbe7dfaac435105/plugin.xml'353 const expectedDependencyValue = 'git+https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver#cc0a604d643107f426ae35276fbe7dfaac435105';354 getPluginNameFromXml.mockReturnValue(pluginName);355 await addPlugin([356 "node",357 "monaca",358 "plugin",359 "add",360 gitUrl361 ],362 projectDir363 );364 expect(request.get.mock.calls[0][0]).toBe(rawFileUrl);365 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);366 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, expectedDependencyValue);367 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});368 });369 test('Specific github branch with .git in the url: https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver.git#cc0a604d643107f426ae35276fbe7dfaac43510',370 async () => {371 const pluginName = "cordova-plugin-camera";372 const gitUrl = 'https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver.git#cc0a604d643107f426ae35276fbe7dfaac43510';373 const rawFileUrl = 'https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver/raw/cc0a604d643107f426ae35276fbe7dfaac43510/plugin.xml'374 const expectedDependencyValue = 'git+https://gitlab.com/creare-com/cordova-plugin-creare-tabsintreceiver.git#cc0a604d643107f426ae35276fbe7dfaac43510';375 getPluginNameFromXml.mockReturnValue(pluginName);376 await addPlugin([377 "node",378 "monaca",379 "plugin",380 "add",381 gitUrl382 ],383 projectDir384 );385 expect(request.get.mock.calls[0][0]).toBe(rawFileUrl);386 expect(fsExtra.writeFileSync.mock.calls[0][0]).toBe(expectedPkgJsonPath);387 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).dependencies).toHaveProperty(pluginName, expectedDependencyValue);388 expect(JSON.parse(fsExtra.writeFileSync.mock.calls[0][1]).cordova.plugins).toHaveProperty(pluginName, {});389 });390});391describe('Error cases', () => {392 test('Unsupported repo type or url: https://google.com/', async () => {393 const pluginName = "cordova-plugin-camera";394 const gitUrl = 'https://google.com/';395 getPluginNameFromXml.mockReturnValue(pluginName);396 expect.assertions(1);397 try {398 await addPlugin([399 "node",400 "monaca",401 "plugin",402 "add",403 gitUrl404 ], projectDir);405 }406 catch (e) {407 expect(e.message).toEqual('No plugin.xml was found in the git repository.');408 }409 });410 test('No package.json found in git repository', async () => {411 const pluginName = "cordova-plugin-camera";412 const gitUrl = 'https://gitlab.com/cordova-plugins/cordova-bluetoothsco';413 getPluginNameFromXml.mockReturnValue(pluginName);414 expect.assertions(1);415 try {416 await addPlugin([417 "node",418 "monaca",419 "plugin",420 "add",421 gitUrl422 ], projectDir);423 }424 catch (e) {425 expect(e.message).toEqual('No package.json was found in the git repository.');426 }427 });428 test('Plugin already exists', async () => {429 const pluginName = "cordova-plugin-camera";430 const projectDir = 'temp';431 const folder = "localPath"432 const pluginPath = path.join(projectDir, folder);433 const expectedPkgJsonPath = path.join(projectDir, 'package.json');434 const expectedFetchJsonPath = path.join(projectDir, 'plugins', 'fetch.json');435 getPluginNameFromXml.mockReturnValue(pluginName);436 loadJson.mockDeps = {437 'cordova-plugin-camera': '1'438 }439 try {440 await addPlugin([441 "node",442 "monaca",443 "plugin",444 "add",445 `file:/${pluginPath}`446 ],447 projectDir448 );449 }450 catch (e) {451 expect(e.message).toEqual('Plugin has been added already: cordova-plugin-camera');452 }453 loadJson.mockDeps = {}454 });455 test('Plugin is outside the root folder', async () => {456 const pluginName = "cordova-plugin-camera";457 const projectDir = 'temp';458 const folder = "localPath"459 const pluginPath = path.join(folder);460 const expectedPkgJsonPath = path.join(projectDir, 'package.json');461 const expectedFetchJsonPath = path.join(projectDir, 'plugins', 'fetch.json');462 getPluginNameFromXml.mockReturnValue(pluginName);463 try {464 await addPlugin([465 "node",466 "monaca",467 "plugin",468 "add",469 `file:/${pluginPath}`470 ], projectDir);471 }472 catch (e) {473 expect(e.message).toEqual('Plugin must be under the project root.');474 }475 });...
test.fromNode.js
Source:test.fromNode.js
...22}23test('normal', function (t) {24 t.test('setup', before);25 t.test('copy stuff', function (t) {26 fs.writeFileSync('input/a.txt', 'a');27 fs.writeFileSync('input/b.txt', 'b');28 fs.writeFileSync('input/c.js', 'c');29 copyfiles(['input/*.txt', 'output'], function (err) {30 t.error(err, 'copyfiles');31 fs.readdir('output/input', function (err, files) {32 t.error(err, 'readdir');33 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');34 t.end();35 });36 });37 });38 t.test('teardown', after);39});40test('modes', function (t) {41 t.test('setup', before);42 t.test('copy stuff', function (t) {43 fs.writeFileSync('input/a.txt', 'a', {44 mode: 3326145 });46 fs.writeFileSync('input/b.txt', 'b');47 fs.writeFileSync('input/c.js', 'c');48 copyfiles(['input/*.txt', 'output'], function (err) {49 t.error(err, 'copyfiles');50 fs.readdir('output/input', function (err, files) {51 t.error(err, 'readdir');52 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');53 t.equals(fs.statSync('output/input/a.txt').mode, 33261, 'correct mode')54 t.end();55 });56 });57 });58 t.test('teardown', after);59});60test('exclude', function (t) {61 t.test('setup', before);62 t.test('copy stuff', function (t) {63 fs.writeFileSync('input/a.txt', 'a');64 fs.writeFileSync('input/b.txt', 'b');65 fs.writeFileSync('input/c.js.txt', 'c');66 fs.writeFileSync('input/d.ps.txt', 'd');67 copyfiles( ['input/*.txt', 'output'], {68 exclude: ['**/*.js.txt', '**/*.ps.txt']69 }, function (err) {70 t.error(err, 'copyfiles');71 fs.readdir('output/input', function (err, files) {72 t.error(err, 'readdir');73 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');74 t.end();75 });76 });77 });78 t.test('teardown', after);79});80test('exclude cl', function (t) {81 t.test('setup', before);82 t.test('copy stuff', function (t) {83 fs.writeFileSync('input/a.txt', 'a');84 fs.writeFileSync('input/b.txt', 'b');85 fs.writeFileSync('input/c.js.txt', 'c');86 fs.writeFileSync('input/d.ps.txt', 'd');87 cp.spawnSync('./copyfiles', ['-e', '**/*.js.txt', '-e', '**/*.ps.txt', 'input/*.txt', 'output']);88 fs.readdir('output/input', function (err, files) {89 t.error(err, 'readdir');90 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');91 t.end();92 });93 });94 t.test('teardown', after);95});96test('all', function (t) {97 t.test('setup', before);98 t.test('copy stuff', function (t) {99 fs.writeFileSync('input/a.txt', 'a');100 fs.writeFileSync('input/b.txt', 'b');101 fs.writeFileSync('input/.c.txt', 'c');102 copyfiles( ['input/*.txt', 'output'], {103 all: true104 }, function (err) {105 t.error(err, 'copyfiles');106 fs.readdir('output/input', function (err, files) {107 t.error(err, 'readdir');108 t.deepEquals(files, ['.c.txt', 'a.txt', 'b.txt'], 'correct number of things');109 t.end();110 });111 });112 });113 t.test('teardown', after);114});115test('all from cl', function (t) {116 t.test('setup', before);117 t.test('copy stuff', function (t) {118 fs.writeFileSync('input/a.txt', 'a');119 fs.writeFileSync('input/b.txt', 'b');120 fs.writeFileSync('input/.c.txt', 'c');121 cp.spawnSync('./copyfiles', ['-a', 'input/*.txt', 'output']);122 fs.readdir('output/input', function (err, files) {123 t.error(err, 'readdir');124 t.deepEquals(files, ['.c.txt', 'a.txt', 'b.txt'], 'correct number of things');125 t.end();126 });127 });128 t.test('teardown', after);129});130test('error on nothing coppied', function (t) {131 t.test('setup', before);132 t.test('copy stuff', function (t) {133 fs.writeFileSync('input/.c.txt', 'c');134 var out = cp.spawnSync('./copyfiles', ['-E', 'input/*.txt', 'output']);135 t.ok(out.status, 'should error');136 t.end();137 });138 t.test('teardown', after);139});140test('all from cl 2', function (t) {141 t.test('setup', before);142 t.test('copy stuff', function (t) {143 fs.writeFileSync('input/a.txt', 'a');144 fs.writeFileSync('input/b.txt', 'b');145 fs.writeFileSync('input/.c.txt', 'c');146 cp.spawnSync('./copyfiles', ['--all', 'input/*.txt', 'output']);147 fs.readdir('output/input', function (err, files) {148 t.error(err, 'readdir');149 t.deepEquals(files, ['.c.txt', 'a.txt', 'b.txt'], 'correct number of things');150 t.end();151 });152 });153 t.test('teardown', after);154});155test('soft', function (t) {156 t.test('setup', before);157 t.test('copy stuff', function (t) {158 mkdirp('output/input/other', function(){159 fs.writeFileSync('input/a.txt', 'inputA');160 fs.writeFileSync('output/input/a.txt', 'outputA');161 t.equal( fs.readFileSync('output/input/a.txt').toString(), 'outputA' )162 fs.writeFileSync('input/b.txt', 'b');163 fs.writeFileSync('input/other/c.txt', 'inputC');164 fs.writeFileSync('output/input/other/c.txt', 'outputC');165 fs.writeFileSync('input/other/d.txt', 'd');166 copyfiles(['input/**/*.txt', 'output'], {soft:true}, function (err) {167 t.error(err, 'copyfiles');168 fs.readdir('output/input', function (err, files) {169 t.error(err, 'readdir');170 t.deepEquals(files, ['a.txt', 'b.txt', 'other'], 'correct number of things');171 t.equal( fs.readFileSync('output/input/a.txt').toString(), 'outputA' )172 t.equal( fs.readFileSync('output/input/b.txt').toString(), 'b')173 t.equal( fs.readFileSync('output/input/other/c.txt').toString(), 'outputC')174 t.end();175 });176 });177 })178 });179 t.test('teardown', after);180});181test('soft from cl', function (t) {182 t.test('setup', before);183 t.test('copy stuff', function (t) {184 mkdirp('output/input/other', function(){185 fs.writeFileSync('input/a.txt', 'inputA');186 fs.writeFileSync('output/input/a.txt', 'outputA');187 t.equal( fs.readFileSync('output/input/a.txt').toString(), 'outputA' )188 fs.writeFileSync('input/b.txt', 'b');189 fs.writeFileSync('input/other/c.txt', 'inputC');190 fs.writeFileSync('output/input/other/c.txt', 'outputC');191 fs.writeFileSync('input/other/d.txt', 'd');192 cp.spawnSync('./copyfiles', ['-s', 'input/**/*.txt', 'output']);193 fs.readdir('output/input', function (err, files) {194 t.error(err, 'readdir');195 t.deepEquals(files, ['a.txt', 'b.txt', 'other'], 'correct number of things');196 t.equal( fs.readFileSync('output/input/a.txt').toString(), 'outputA' )197 t.equal( fs.readFileSync('output/input/b.txt').toString(), 'b')198 t.equal( fs.readFileSync('output/input/other/c.txt').toString(), 'outputC')199 t.end();200 });201 });202 });203 t.test('teardown', after);204});205test('soft from cl 2', function (t) {206 t.test('setup', before);207 t.test('copy stuff', function (t) {208 mkdirp('output/input/other', function(){209 fs.writeFileSync('input/a.txt', 'inputA');210 fs.writeFileSync('output/input/a.txt', 'outputA');211 t.equal( fs.readFileSync('output/input/a.txt').toString(), 'outputA' )212 fs.writeFileSync('input/b.txt', 'b');213 fs.writeFileSync('input/other/c.txt', 'inputC');214 fs.writeFileSync('output/input/other/c.txt', 'outputC');215 fs.writeFileSync('input/other/d.txt', 'd');216 cp.spawnSync('./copyfiles', ['--soft', 'input/**/*.txt', 'output']);217 fs.readdir('output/input', function (err, files) {218 t.error(err, 'readdir');219 t.deepEquals(files, ['a.txt', 'b.txt', 'other'], 'correct number of things');220 t.equal( fs.readFileSync('output/input/a.txt').toString(), 'outputA' )221 t.equal( fs.readFileSync('output/input/b.txt').toString(), 'b')222 t.equal( fs.readFileSync('output/input/other/c.txt').toString(), 'outputC')223 t.end();224 });225 });226 });227 t.test('teardown', after);228});229test('with up', function (t) {230 t.test('setup', before);231 t.test('copy stuff', function (t) {232 fs.writeFileSync('input/a.txt', 'a');233 fs.writeFileSync('input/b.txt', 'b');234 fs.writeFileSync('input/c.js', 'c');235 copyfiles(['input/*.txt', 'output'], 1, function (err) {236 t.error(err, 'copyfiles');237 fs.readdir('output', function (err, files) {238 t.error(err, 'readdir');239 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');240 t.end();241 });242 });243 });244 t.test('teardown', after);245});246test('with up cl', function (t) {247 t.test('setup', before);248 t.test('copy stuff', function (t) {249 fs.writeFileSync('input/a.txt', 'a');250 fs.writeFileSync('input/b.txt', 'b');251 fs.writeFileSync('input/c.js', 'c');252 cp.spawnSync('./copyfiles', ['-u', '1', 'input/*.txt', 'output']);253 fs.readdir('output', function (err, files) {254 t.error(err, 'readdir');255 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');256 t.end();257 });258 });259 t.test('teardown', after);260});261test('with copyup', function (t) {262 t.test('setup', before);263 t.test('copy stuff', function (t) {264 fs.writeFileSync('input/a.txt', 'a');265 fs.writeFileSync('input/b.txt', 'b');266 fs.writeFileSync('input/c.js', 'c');267 cp.spawnSync('./copyup', ['input/*.txt', 'output']);268 fs.readdir('output', function (err, files) {269 t.error(err, 'readdir');270 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');271 t.end();272 });273 });274 t.test('teardown', after);275});276test('with up 2', function (t) {277 t.test('setup', before);278 t.test('copy stuff', function (t) {279 fs.writeFileSync('input/other/a.txt', 'a');280 fs.writeFileSync('input/other/b.txt', 'b');281 fs.writeFileSync('input/other/c.js', 'c');282 copyfiles(['input/**/*.txt', 'output'], 2, function (err) {283 t.error(err, 'copyfiles');284 fs.readdir('output', function (err, files) {285 t.error(err, 'readdir');286 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');287 t.end();288 });289 });290 });291 t.test('teardown', after);292});293test('flatten', function (t) {294 t.test('setup', before);295 t.test('copy stuff', function (t) {296 fs.writeFileSync('input/other/a.txt', 'a');297 fs.writeFileSync('input/b.txt', 'b');298 fs.writeFileSync('input/other/c.js', 'c');299 copyfiles(['input/**/*.txt', 'output'], true, function (err) {300 t.error(err, 'copyfiles');301 fs.readdir('output', function (err, files) {302 t.error(err, 'readdir');303 t.deepEquals(files, ['a.txt', 'b.txt'], 'correct number of things');304 t.end();305 });306 });307 });308 t.test('teardown', after);...
test-trace-events-fs-sync.js
Source:test-trace-events-fs-sync.js
...13if (!common.isWindows) {14 gid = process.getgid();15 uid = process.getuid();16}17tests['fs.sync.access'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +18 'fs.accessSync("fs.txt");' +19 'fs.unlinkSync("fs.txt")';20tests['fs.sync.chmod'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +21 'fs.chmodSync("fs.txt",100);' +22 'fs.unlinkSync("fs.txt")';23tests['fs.sync.chown'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +24 'fs.chownSync("fs.txt",' + uid + ',' + gid + ');' +25 'fs.unlinkSync("fs.txt")';26tests['fs.sync.close'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +27 'fs.unlinkSync("fs.txt")';28tests['fs.sync.copyfile'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +29 'fs.copyFileSync("fs.txt","a.txt");' +30 'fs.unlinkSync("fs.txt")';31tests['fs.sync.fchmod'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +32 'const fd = fs.openSync("fs.txt", "r+");' +33 'fs.fchmodSync(fd,100);' +34 'fs.unlinkSync("fs.txt")';35tests['fs.sync.fchown'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +36 'const fd = fs.openSync("fs.txt", "r+");' +37 'fs.fchownSync(fd,' + uid + ',' + gid + ');' +38 'fs.unlinkSync("fs.txt")';39tests['fs.sync.fdatasync'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +40 'const fd = fs.openSync("fs.txt", "r+");' +41 'fs.fdatasyncSync(fd);' +42 'fs.unlinkSync("fs.txt")';43tests['fs.sync.fstat'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +44 'fs.readFileSync("fs.txt");' +45 'fs.unlinkSync("fs.txt")';46tests['fs.sync.fsync'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +47 'const fd = fs.openSync("fs.txt", "r+");' +48 'fs.fsyncSync(fd);' +49 'fs.unlinkSync("fs.txt")';50tests['fs.sync.ftruncate'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +51 'const fd = fs.openSync("fs.txt", "r+");' +52 'fs.ftruncateSync(fd, 1);' +53 'fs.unlinkSync("fs.txt")';54tests['fs.sync.futimes'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +55 'const fd = fs.openSync("fs.txt", "r+");' +56 'fs.futimesSync(fd,1,1);' +57 'fs.unlinkSync("fs.txt")';58tests['fs.sync.lchown'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +59 'fs.lchownSync("fs.txt",' + uid + ',' + gid + ');' +60 'fs.unlinkSync("fs.txt")';61tests['fs.sync.link'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +62 'fs.linkSync("fs.txt", "linkx");' +63 'fs.unlinkSync("linkx");' +64 'fs.unlinkSync("fs.txt")';65tests['fs.sync.lstat'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +66 'fs.lstatSync("fs.txt");' +67 'fs.unlinkSync("fs.txt")';68tests['fs.sync.mkdir'] = 'fs.mkdirSync("fstemp");' +69 'fs.rmdirSync("fstemp")';70tests['fs.sync.mkdtemp'] = 'const fp = fs.mkdtempSync("fstest");' +71 'fs.rmdirSync(fp)';72tests['fs.sync.open'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +73 'fs.unlinkSync("fs.txt")';74tests['fs.sync.read'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +75 'fs.readFileSync("fs.txt");' +76 'fs.unlinkSync("fs.txt")';77tests['fs.sync.readdir'] = 'fs.readdirSync("./")';78tests['fs.sync.realpath'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +79 'fs.linkSync("fs.txt", "linkx");' +80 'fs.realpathSync.native("linkx");' +81 'fs.unlinkSync("linkx");' +82 'fs.unlinkSync("fs.txt")';83tests['fs.sync.rename'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +84 'fs.renameSync("fs.txt","xyz.txt"); ' +85 'fs.unlinkSync("xyz.txt")';86tests['fs.sync.rmdir'] = 'fs.mkdirSync("fstemp");' +87 'fs.rmdirSync("fstemp")';88tests['fs.sync.stat'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +89 'fs.statSync("fs.txt");' +90 'fs.unlinkSync("fs.txt")';91tests['fs.sync.unlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +92 'fs.linkSync("fs.txt", "linkx");' +93 'fs.unlinkSync("linkx");' +94 'fs.unlinkSync("fs.txt")';95tests['fs.sync.utimes'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +96 'fs.utimesSync("fs.txt",1,1);' +97 'fs.unlinkSync("fs.txt")';98tests['fs.sync.write'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +99 'fs.unlinkSync("fs.txt")';100// On windows, we need permissions to test symlink and readlink.101// We'll only try to run these tests if we have enough privileges.102if (common.canCreateSymLink()) {103 tests['fs.sync.symlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +104 'fs.symlinkSync("fs.txt", "linkx");' +105 'fs.unlinkSync("linkx");' +106 'fs.unlinkSync("fs.txt")';107 tests['fs.sync.readlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +108 'fs.symlinkSync("fs.txt", "linkx");' +109 'fs.readlinkSync("linkx");' +110 'fs.unlinkSync("linkx");' +111 'fs.unlinkSync("fs.txt")';112}113const tmpdir = require('../common/tmpdir');114tmpdir.refresh();115process.chdir(tmpdir.path);116for (const tr in tests) {117 const proc = cp.spawnSync(process.execPath,118 [ '--trace-events-enabled',119 '--trace-event-categories', 'node.fs.sync',120 '-e', tests[tr] ],121 { encoding: 'utf8' });...
index.js
Source:index.js
...1415const entry = (comment, clip) => {16 const filePath = './test_out/separate/' + clip1718 fs.writeFileSync(filePath, comment, { flag: 'a' })19 fs.writeFileSync(filePath, '\n', { flag: 'a' })20 fs.writeFileSync(allPath, comment, { flag: 'a' })21 fs.writeFileSync(allPath, '\n', { flag: 'a' })2223 fs.writeFileSync(filePath, clip, { flag: 'a' })24 fs.writeFileSync(filePath, '\n', { flag: 'a' })25 fs.writeFileSync(allPath, clip, { flag: 'a' })26 fs.writeFileSync(allPath, '\n', { flag: 'a' })2728 const bits = clipToBits(clip)29 fs.writeFileSync(filePath, bits, { flag: 'a' })30 fs.writeFileSync(filePath, '\n', { flag: 'a' })31 fs.writeFileSync(allPath, bits, { flag: 'a' })32 fs.writeFileSync(allPath, '\n', { flag: 'a' })3334 const dense = bitsToDense(bits)35 const denseString = JSON.stringify(dense, null, 2)36 fs.writeFileSync(filePath, denseString, { flag: 'a' })37 fs.writeFileSync(filePath, '\n', { flag: 'a' })38 fs.writeFileSync(allPath, denseString, { flag: 'a' })39 fs.writeFileSync(allPath, '\n', { flag: 'a' })4041 const sparse = denseToSparse(dense)42 const sparseString = JSON.stringify(sparse, null, 2)43 fs.writeFileSync(filePath, sparseString, { flag: 'a' })44 fs.writeFileSync(filePath, '\n', { flag: 'a' })45 fs.writeFileSync(allPath, sparseString, { flag: 'a' })46 fs.writeFileSync(allPath, '\n', { flag: 'a' })4748 const denseFromSparse = sparseToDense(sparse)49 const denseFromSparseString = JSON.stringify(denseFromSparse, null, 2)50 fs.writeFileSync(filePath, denseFromSparseString, { flag: 'a' })51 fs.writeFileSync(filePath, '\n', { flag: 'a' })52 fs.writeFileSync(allPath, denseFromSparseString, { flag: 'a' })53 fs.writeFileSync(allPath, '\n', { flag: 'a' })5455 const annotatedBits = denseToBits(denseFromSparse)56 fs.writeFileSync(filePath, annotatedBits, { flag: 'a' })57 fs.writeFileSync(filePath, '\n', { flag: 'a' })58 fs.writeFileSync(allPath, annotatedBits, { flag: 'a' })59 fs.writeFileSync(allPath, '\n', { flag: 'a' })6061 const roundtripClip = bitsToClip(cleanBits(annotatedBits))62 fs.writeFileSync(filePath, roundtripClip, { flag: 'a' })63 fs.writeFileSync(filePath, '\n', { flag: 'a' })64 fs.writeFileSync(allPath, roundtripClip, { flag: 'a' })65 fs.writeFileSync(allPath, '\n', { flag: 'a' })6667 if (roundtripClip !== clip) {68 console.error(`Clip string ${clip} didn't roundtrip properly`)69 }7071 fs.writeFileSync(allPath, '---\n', { flag: 'a' })72}7374entry('(0, 0, 1) -> (15, 0)', 'AAAG')75entry('(0, 9, 1) -> (15, 0)', 'FAAmhB')76entry('(9, 0, 1) -> (15, 0)', 'FAIDhB')77entry('(0, 0, 1) -> (0, 1)', 'AAIAN')78entry('(0, 0, 1) -> (2, 1)', 'AAICN')79entry('(0, 0, 1) -> (14, 1)', 'AAIcN')80entry('(0, 0, 1) -> (0, 250)', 'AAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN')81entry('(0, 0, 1) -> (14, 250)', 'AAIcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN')82entry('(0, 0, 1) -> (14, 251)', 'AAIcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0')83entry('(0, 0, 1) -> (14, 252)', 'AAIcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQD')84entry('(0, 0, 1) -> (14, 253)', 'AAIcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN')85
...
config.js
Source:config.js
1import Config from '../src/config.js';2import Emitter from '../src/emitter.js';3import { expect } from 'chai';4import sinon from 'sinon';5import fs from 'fs';6import os from 'os';7describe('Config', () => {8 let emitter;9 let config;10 let ini_content;11 let credentials;12 beforeEach(() => {13 emitter = sinon.createStubInstance(Emitter);14 config = new Config(emitter);15 ini_content = [16 '[credentials]', 17 'api_key=123', 18 'api_secret=abc',19 ''20 ].join(os.EOL);21 credentials = { credentials: { api_key: '123', api_secret: 'abc'}};22 });23 it('should export a Config object', () => {24 expect(Config).to.not.be.null;25 expect(Config.name).to.equal('Config');26 });27 describe('.read', () => {28 it('should read out the file contents', () => {29 const readFileSync = fs.readFileSync;30 fs.readFileSync = function() {31 return ini_content;32 };33 const data = config.read();34 expect(data).to.eql(credentials);35 fs.readFileSync = readFileSync;36 });37 });38 describe('.write', () => {39 it('should write out the data', () => {40 const writeFileSync = fs.writeFileSync;41 fs.writeFileSync = function(filename, data){42 expect(filename).to.match(/\/\.nexmorc$/);43 expect(data).to.equal(ini_content);44 };45 config.write(credentials);46 fs.writeFileSync = writeFileSync;47 });48 });49 describe('.readFilename', () => {50 it('should return the home path', () => {51 if (process.env == 'win32') {52 expect(config.readFilename()).to.have.string(process.env['USERPROFILE']);53 } else {54 expect(config.readFilename()).to.have.string(process.env['HOME']);55 }56 });57 it('should return the local path if a .nexmorc file exists locally', () => {58 const cwd = process.cwd();59 const existsSync = fs.existsSync;60 fs.existsSync = function() {61 return true;62 };63 expect(config.readFilename()).to.have.string(cwd);64 fs.existsSync = existsSync;65 });66 });67 describe('.writeFilename', () => {68 it('should return the home dir', () => {69 if (process.env == 'win32') {70 expect(config.writeFilename()).to.have.string(process.env['USERPROFILE']);71 } else {72 expect(config.writeFilename()).to.have.string(process.env['HOME']);73 }74 });75 it('should return the local path if specified', () => {76 expect(config.writeFilename(true)).to.have.string(process.cwd());77 });78 });79 describe('.putAndSave', () => {80 it('should write the new data', () => {81 const writeFileSync = fs.writeFileSync;82 fs.writeFileSync = function(filename, data){83 expect(filename).to.match(config.readFilename());84 expect(data).to.equal(ini_content);85 };86 config.putAndSave(credentials, false);87 fs.writeFileSync = writeFileSync;88 });89 it('should merge additional data', () => {90 const initial_content = `[credentials]91api_key=12392api_secret=abc93`;94 const expected_content = `[credentials]95api_key=23496api_secret=abc97[extras]98foobar=199`;100 const writeFileSync = fs.writeFileSync;101 const readFileSync = fs.readFileSync;102 fs.readFileSync = function() {103 return initial_content;104 };105 fs.writeFileSync = function(filename, data){106 expect(filename).to.match(config.readFilename());107 expect(data).to.equal(expected_content);108 };109 config.putAndSave({110 'credentials': {111 'api_key': 234112 },113 'extras': {114 'foobar': 1115 }116 }, true);117 fs.readFileSync = readFileSync;118 fs.writeFileSync = writeFileSync;119 });120 });...
vfs.js
Source:vfs.js
...4const virtualfs = require("virtualfs");5// Setup the virtual file system.6const fs = new virtualfs.VirtualFS();7fs.mkdirpSync("third_party/todomvc/react");8fs.writeFileSync(9 "third_party/angular-material-1.1.8.css",10 require("raw-loader!../third_party/angular-material-1.1.8.css")11);12fs.writeFileSync(13 "third_party/backbone-1.1.0.js",14 require("raw-loader!../third_party/backbone-1.1.0.js")15);16fs.writeFileSync(17 "third_party/bootstrap-4.0.0.css",18 require("raw-loader!../third_party/bootstrap-4.0.0.css")19);20fs.writeFileSync(21 "third_party/foundation-6.4.2.css",22 require("raw-loader!../third_party/foundation-6.4.2.css")23);24fs.writeFileSync(25 "third_party/jquery-3.2.1.js",26 require("raw-loader!../third_party/jquery-3.2.1.js")27);28fs.writeFileSync(29 "third_party/coffeescript-lexer-2.0.1.coffee",30 require("raw-loader!../third_party/coffeescript-lexer-2.0.1.coffee")31);32fs.writeFileSync(33 "third_party/lodash.core-4.17.4.js",34 require("raw-loader!../third_party/lodash.core-4.17.4.js")35);36fs.writeFileSync(37 "third_party/lodash.min-4.17.4.js.map",38 require("raw-loader!../third_party/lodash.min-4.17.4.js.map")39);40fs.writeFileSync(41 "third_party/mootools-core-1.6.0.js",42 require("raw-loader!../third_party/mootools-core-1.6.0.js")43);44fs.writeFileSync(45 "third_party/preact-8.2.5.js",46 require("raw-loader!../third_party/preact-8.2.5.js")47);48fs.writeFileSync(49 "third_party/preact-8.2.5.js.map",50 require("raw-loader!../third_party/preact-8.2.5.js.map")51);52fs.writeFileSync(53 "third_party/redux.min-3.7.2.js",54 require("raw-loader!../third_party/redux.min-3.7.2.js")55);56fs.writeFileSync(57 "third_party/source-map.min-0.5.7.js.map",58 require("raw-loader!../third_party/source-map.min-0.5.7.js.map")59);60fs.writeFileSync(61 "third_party/speedometer-es2015-test-2.0.js",62 require("raw-loader!../third_party/speedometer-es2015-test-2.0.js")63);64fs.writeFileSync(65 "third_party/todomvc/react/app.jsx",66 require("raw-loader!../third_party/todomvc/react/app.jsx")67);68fs.writeFileSync(69 "third_party/todomvc/react/footer.jsx",70 require("raw-loader!../third_party/todomvc/react/footer.jsx")71);72fs.writeFileSync(73 "third_party/todomvc/react/todoItem.jsx",74 require("raw-loader!../third_party/todomvc/react/todoItem.jsx")75);76fs.writeFileSync(77 "third_party/todomvc/typescript-angular.ts",78 require("raw-loader!../third_party/todomvc/typescript-angular.ts")79);80fs.writeFileSync(81 "third_party/underscore-1.8.3.js",82 require("raw-loader!../third_party/underscore-1.8.3.js")83);84fs.writeFileSync(85 "third_party/underscore.min-1.8.3.js.map",86 require("raw-loader!../third_party/underscore.min-1.8.3.js.map")87);88fs.writeFileSync(89 "third_party/vue.runtime.esm-nobuble-2.4.4.js",90 require("raw-loader!../third_party/vue.runtime.esm-nobuble-2.4.4.js")91);...
generateGrammar.js
Source:generateGrammar.js
1const fs = require('fs')2const configData = JSON.parse(fs.readFileSync('config.json', 'utf-8'))3const phones = configData['phones']4const filename = `${__dirname}/${configData['grammarFile']}`5fs.writeFileSync(filename, '<?xml version="1.0" encoding="UTF-8"?> \n\n')6fs.writeFileSync(filename, '<grammar xml:lang="en-US" tag-format="semantics-ms/1.0" version="1.0" root="PersyColor" mode="voice" xmlns="http://www.w3.org/2001/06/grammar"> \n', {flag: 'a'})7fs.writeFileSync(filename, '<rule id="PersyColor" scope="public"> \n', {flag: 'a'})8fs.writeFileSync(filename, ' <item>\n', {flag: 'a'})9fs.writeFileSync(filename, ' <item repeat="0-1"><ruleref uri="#UMFILLER"/></item> \n', {flag: 'a'})10fs.writeFileSync(filename, ' <item>\n', {flag: 'a'})11fs.writeFileSync(filename, ' <one-of>\n', {flag: 'a'})12phones.forEach(phone => {13 fs.writeFileSync(filename, ` <item>${phone["location"].toLowerCase()}<tag>$._value = \"${phone['location']}\";</tag></item>\n`, {flag: 'a'})14});15fs.writeFileSync(filename, ' </one-of>\n', {flag: 'a'})16fs.writeFileSync(filename, ' </item>\n', {flag: 'a'})17fs.writeFileSync(filename, ' <item repeat="0-1"><ruleref uri="#TRAILERS"/></item> \n', {flag: 'a'})18fs.writeFileSync(filename, ' </item>\n', {flag: 'a'})19fs.writeFileSync(filename, '</rule>\n\n', {flag: 'a'})20fs.writeFileSync(filename, '<rule id="UMFILLER">\n', {flag: 'a'})21fs.writeFileSync(filename, ' <one-of>\n', {flag: 'a'})22fs.writeFileSync(filename, ' <item> uh </item>\n', {flag: 'a'})23fs.writeFileSync(filename, ' <item> um </item>\n', {flag: 'a'})24fs.writeFileSync(filename, ' <item> hm </item>\n', {flag: 'a'})25fs.writeFileSync(filename, ' <item> ah </item>\n', {flag: 'a'})26fs.writeFileSync(filename, ' <item> er </item>\n', {flag: 'a'})27fs.writeFileSync(filename, ' </one-of>\n', {flag: 'a'})28fs.writeFileSync(filename, '</rule>\n\n', {flag: 'a'})29fs.writeFileSync(filename, '<rule id="TRAILERS">\n', {flag: 'a'})30fs.writeFileSync(filename, ' <one-of>\n', {flag: 'a'})31fs.writeFileSync(filename, ' <item> maam </item>\n', {flag: 'a'})32fs.writeFileSync(filename, ' <item> sir </item>\n', {flag: 'a'})33fs.writeFileSync(filename, ' </one-of>\n', {flag: 'a'})34fs.writeFileSync(filename, '</rule>\n\n', {flag: 'a'})...
Using AI Code Generation
1const { writeFileSync } = require('fs');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.screenshot({ path: 'google.png' });8 writeFileSync('google.html', await page.content());9 await browser.close();10})();
Using AI Code Generation
1const fs = require('fs');2const path = require('path');3const { chromium } = require('playwright');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.screenshot({ path: 'example.png' });9 await browser.close();10 const screenshot = fs.readFileSync(path.join(__dirname, 'example.png'));11 fs.writeFileSync(path.join(__dirname, 'example2.png'), screenshot);12})();
Using AI Code Generation
1const fs = require('fs');2const path = require('path');3const { chromium } = require('playwright');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.screenshot({ path: 'google.png' });9 const data = await page.screenshot();10 fs.writeFileSync(path.join(__dirname, 'google.png'), data);11 await browser.close();12})();
Using AI Code Generation
1const fs = require('fs');2const path = require('path');3const { chromium } = require('playwright');4(async () => {5 const browser = await chromium.launch({6 });7 const context = await browser.newContext();8 const page = await context.newPage();9 const userAgent = await page.evaluate(() => navigator.userAgent);10 const filePath = path.join(__dirname, 'userAgent.txt');11 fs.writeFileSync(filePath, userAgent);12 await browser.close();13})();
Using AI Code Generation
1const fs = require('fs');2const path = require('path');3const { chromium } = require('playwright');4(async () => {5 const browser = await chromium.launch();6 const page = await browser.newPage();7 await page.screenshot({ path: path.join(__dirname, 'screenshot.png') });8 await browser.close();9})();
Using AI Code Generation
1const playwright = require('playwright');2const fs = require('fs');3const { chromium } = require('playwright');4(async () => {5 const browser = await chromium.launch({ headless: false });6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.screenshot({ path: 'google.png' });9 await browser.close();10 fs.writeFileSync('test.js', 'console.log("Hello World");');11})();12const playwright = require('playwright');13const fs = require('fs');14const { chromium } = require('playwright');15(async () => {16 const browser = await chromium.launch({ headless: false });17 const context = await browser.newContext();18 const page = await context.newPage();19 await page.screenshot({ path: 'google.png' });20 await browser.close();21 fs.writeFile('test.js', 'console.log("Hello World");', (err) => {22 if (err) {23 console.log(err);24 }25 });26})();27const playwright = require('playwright');28const fs = require('fs');29const { chromium } = require
Using AI Code Generation
1const { writeFileSync } = require('playwright/lib/utils/utils');2writeFileSync('test.txt', 'Hello World!');3const { readFileSync } = require('playwright/lib/utils/utils');4console.log(readFileSync('test.txt', 'utf8'));5const { readdirSync } = require('playwright/lib/utils/utils');6console.log(readdirSync('./'));7const { mkdirSync } = require('playwright/lib/utils/utils');8mkdirSync('test');9const { rmdirSync } = require('playwright/lib/utils/utils');10rmdirSync('test');11const { unlinkSync } = require('playwright/lib/utils/utils');12unlinkSync('test.txt');13const { existsSync } = require('playwright/lib/utils/utils');14console.log(existsSync('test.txt'));15const { lstatSync } = require('playwright/lib/utils/utils');16console.log(lstatSync('test.txt'));17const { copyFileSync } = require('playwright/lib/utils/utils');18copyFileSync('test.txt', 'test1.txt');19const { renameSync } = require('playwright/lib/utils/utils');20renameSync('test.txt', 'test1.txt');21const { statSync } = require('playwright/lib/utils/utils');22console.log(statSync('test.txt'));23const { realpathSync } = require('playwright/lib/utils/utils');24console.log(realpathSync('test.txt'));25const { chmodSync } = require('playwright/lib/utils/utils');26chmodSync('test.txt', 0o777);27const { lchmodSync } = require('playwright/lib/utils/utils');28lchmodSync('test.txt', 0o777);
Using AI Code Generation
1const fs = require('playwright/lib/utils/fs');2fs.writeFileSync('test.txt', 'Hello World!');3const fs = require('playwright/lib/utils/fs');4fs.writeFileSync('test.txt', 'Hello World!');5const fs = require('playwright/lib/utils/fs');6fs.writeFileSync('test.txt', 'Hello World!');7const fs = require('playwright/lib/utils/fs');8fs.writeFileSync('test.txt', 'Hello World!');
Using AI Code Generation
1const fs = require('fs');2const path = require('path');3const { chromium } = require('playwright');4const { setTestTimeout } = require('@playwright/test');5setTestTimeout(60000);6(async () => {7 const browser = await chromium.launch();8 const context = await browser.newContext();9 const page = await context.newPage();10 const screenshots = path.join(__dirname, 'screenshots');11 if (!fs.existsSync(screenshots))12 fs.mkdirSync(screenshots);13 await page.screenshot({ path: path.join(screenshots, `example.png`) });14 await browser.close();15})();
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!