How to use dirPath method in Playwright Internal

Best JavaScript code snippet using playwright-internal

babel.test.js

Source:babel.test.js Github

copy

Full Screen

1'use strict';2const path = require('path');3const fs = require('fs');4const dirTree = require('directory-tree');5const commandBuild = require('./test-utils/command-build');6const generateFixture = require('./test-utils/generate-fixture');7const stubNodeModule = require('./test-utils/create-stub-node-module');8jest.setTimeout(15 * 1000);9// Gets the file contents in webpack's build output10const getFileContent = (tree, startsWith) => {11 const filename = tree.children12 .find(t => t.name === 'js')13 .children.find(t => t.name.startsWith(startsWith)).path;14 return fs.readFileSync(filename, 'utf-8');15};16test("Doesn't transpile arrow function for newer browser values", () => {17 const fixture = generateFixture({18 src: {19 'index.js': `20 window.foo = ()=>'UNDERREACT_TEST_RETURN_VALUE';21 `22 },23 'underreact.config.js': `24 module.exports = {browserslist: ['chrome 67']}25 `26 });27 return fixture28 .then(dirPath => {29 return commandBuild({ cwd: dirPath }).then(() => dirPath);30 })31 .then(dirPath => {32 const tree = dirTree(path.join(dirPath, '_site', 'underreact-assets'));33 const mainFileContent = getFileContent(tree, 'main');34 expect(mainFileContent).toMatch(/=>"UNDERREACT_TEST_RETURN_VALUE"/);35 });36});37test('Transpiles arrow function for older browsers by default', () => {38 const fixture = generateFixture({39 src: {40 'index.js': `41 window.foo = () => 'UNDERREACT_TEST_RETURN_VALUE';42 `43 }44 });45 return fixture46 .then(dirPath => {47 return commandBuild({ cwd: dirPath }).then(() => dirPath);48 })49 .then(dirPath => {50 const tree = dirTree(path.join(dirPath, '_site', 'underreact-assets'));51 const mainFileContent = getFileContent(tree, 'main');52 expect(mainFileContent).toMatch(/return"UNDERREACT_TEST_RETURN_VALUE"/);53 });54});55test('Browserslist takes development env value', () => {56 const fixture = generateFixture({57 src: {58 'index.js': `59 window.foo = ()=>'UNDERREACT_TEST_RETURN_VALUE';60 `61 },62 'underreact.config.js': `63 module.exports = { 64 browserslist: {65 production: ['ie 11'],66 development: ['chrome 67']67 }68 }69 `70 });71 return fixture72 .then(dirPath => {73 return commandBuild({ cwd: dirPath, args: ['-m=development'] }).then(74 () => dirPath75 );76 })77 .then(dirPath => {78 const tree = dirTree(path.join(dirPath, '_site', 'underreact-assets'));79 const mainFileContent = getFileContent(tree, 'main');80 expect(mainFileContent).toMatch(/=> 'UNDERREACT_TEST_RETURN_VALUE'/);81 });82});83test('Reads browserslist from package.json', () => {84 const fixture = generateFixture({85 src: {86 'index.js': `87 window.foo = () => 'UNDERREACT_TEST_RETURN_VALUE';88 `89 },90 'package.json': `{91 "browserslist": [92 "chrome 67"93 ]94 }`95 });96 return fixture97 .then(dirPath => {98 return commandBuild({ cwd: dirPath }).then(() => dirPath);99 })100 .then(dirPath => {101 const tree = dirTree(path.join(dirPath, '_site', 'underreact-assets'));102 const mainFileContent = getFileContent(tree, 'main');103 expect(mainFileContent).toMatch(/=>"UNDERREACT_TEST_RETURN_VALUE"/);104 });105});106test('Throws an error when using flow without flow plugin', () => {107 const build = generateFixture({108 src: {109 'index.js': `110 // @flow111 var t: number = 5;112 `113 },114 'babel.config.js': `115 module.exports = {116 presets: []117 }118 `119 }).then(dirPath => commandBuild({ cwd: dirPath }));120 return Promise.resolve()121 .then(() => expect(build).rejects.toMatch(/SyntaxError:/))122 .then(() => expect(build).rejects.toMatch(/ERROR: Compilation error./));123});124test('Parses flow when using correct plugin', () => {125 const babelPresetMapbox = require.resolve('../packages/babel-preset-mapbox');126 const babelPluginFlowStrip = require.resolve(127 '@babel/plugin-transform-flow-strip-types'128 );129 const build = generateFixture({130 src: {131 'index.js': `132 // @flow133 var t: number = 5;134 `135 },136 'babel.config.js': `137 module.exports = {138 presets: ['${babelPresetMapbox}'],139 plugins: ['${babelPluginFlowStrip}']140 }141 `142 }).then(dirPath => commandBuild({ cwd: dirPath }));143 return Promise.resolve()144 .then(() =>145 expect(build).resolves.toMatch(/Using an external Babel config/)146 )147 .then(() => expect(build).resolves.toMatch(/Finished/));148});149test('Converts es6 in node_modules by default', () => {150 const build = generateFixture({151 node_modules: {152 react: stubNodeModule({153 moduleName: 'react',154 content: `155 window.foo = () => 'UNDERREACT_TEST_RETURN_VALUE';156 `157 })158 },159 src: {160 'index.js': `161 window.react = require('react');162 `163 }164 }).then(dirPath => commandBuild({ cwd: dirPath }).then(() => dirPath));165 return build.then(dirPath => {166 const tree = dirTree(path.join(dirPath, '_site', 'underreact-assets'));167 const vendorContent = getFileContent(tree, 'vendor');168 expect(vendorContent).toMatch(/return"UNDERREACT_TEST_RETURN_VALUE"/);169 });170});171test("Doesn't convert es6 in node_modules when disabled", () => {172 const build = generateFixture({173 node_modules: {174 react: stubNodeModule({175 moduleName: 'react',176 content: `177 window.foo = () => 'UNDERREACT_TEST_RETURN_VALUE';178 `179 })180 },181 src: {182 'index.js': `183 window.react = require('react');184 `185 },186 'underreact.config.js': `187 module.exports = { 188 compileNodeModules: false189 }190 `191 }).then(dirPath => commandBuild({ cwd: dirPath }).then(() => dirPath));192 return build.then(dirPath => {193 const tree = dirTree(path.join(dirPath, '_site', 'underreact-assets'));194 const vendorContent = getFileContent(tree, 'vendor');195 expect(vendorContent).toMatch(/=>"UNDERREACT_TEST_RETURN_VALUE"/);196 });197});198test('Selectively converts es6 in node_modules when using compileNodeModules', () => {199 const babelPresetMapbox = require.resolve('../packages/babel-preset-mapbox');200 const build = generateFixture({201 node_modules: {202 react: stubNodeModule({203 moduleName: 'react',204 content: `205 window.react = () => 'UNDERREACT_TEST_RETURN_VALUE';206 `207 }),208 redux: stubNodeModule({209 moduleName: 'redux',210 content: `211 window.redux = () => 'UNDERREACT_TEST_RETURN_VALUE';212 `213 })214 },215 'underreact.config.js': `216 module.exports = { 217 compileNodeModules: ['redux']218 }219 `,220 src: {221 'index.js': `222 require('react');223 require('redux');224 `225 },226 'babel.config.js': `227 module.exports = {228 presets: ['${babelPresetMapbox}'],229 }230 `231 }).then(dirPath => commandBuild({ cwd: dirPath }).then(() => dirPath));232 return build.then(dirPath => {233 const tree = dirTree(path.join(dirPath, '_site', 'underreact-assets'));234 // `react` would go into vendor chunk, since we manually inject in `urc.vendorModules`235 // This would make it easier test stringing and asserting the correct behaviour.236 const vendorContent = getFileContent(tree, 'vendor');237 expect(vendorContent).toMatch(/=>"UNDERREACT_TEST_RETURN_VALUE"/);238 // redux would go into main chunk, since it is not a part of `urc.vendorModules`239 const mainContent = getFileContent(tree, 'main');240 expect(mainContent).toMatch(/return"UNDERREACT_TEST_RETURN_VALUE"/);241 });...

Full Screen

Full Screen

test.async.js

Source:test.async.js Github

copy

Full Screen

1/* global require, describe, it */2'use strict';3var mpath = './../lib/async.js';4// MODULES //5var chai = require( 'chai' ),6 mkdirp = require( 'mkdirp' ),7 path = require( 'path' ),8 fs = require( 'fs' ),9 proxyquire = require( 'proxyquire' ),10 cp = require( mpath );11// VARIABLES //12var expect = chai.expect,13 assert = chai.assert;14// TESTS //15describe( 'async', function tests() {16 it( 'should export a function', function test() {17 expect( cp ).to.be.a( 'function' );18 });19 it( 'should throw an error if not provided a destination', function test() {20 expect( foo ).to.throw( Error );21 function foo() {22 cp();23 }24 });25 it( 'should throw an error if not provided a valid destination directory', function test() {26 var values = [27 5,28 null,29 true,30 undefined,31 NaN,32 [],33 {},34 function(){}35 ];36 for ( var i = 0; i < values.length; i++ ) {37 expect( badValue( values[i] ) ).to.throw( TypeError );38 }39 function badValue( value ) {40 return function() {41 cp( value );42 };43 }44 });45 it( 'should throw an error if not provided a valid options argument', function test() {46 var values = [47 'beep',48 5,49 null,50 true,51 undefined,52 NaN,53 [],54 // function(){} // allowed as fcn is variadic55 ];56 for ( var i = 0; i < values.length; i++ ) {57 expect( badValue1( values[i] ) ).to.throw( TypeError );58 expect( badValue2( values[i] ) ).to.throw( TypeError );59 }60 function badValue1( value ) {61 return function() {62 cp( './beep/boop', value );63 };64 }65 function badValue2( value ) {66 return function() {67 cp( './beep/boop', value, function(){} );68 };69 }70 });71 it( 'should throw an error if provided an invalid option', function test() {72 var values = [73 5,74 null,75 true,76 undefined,77 NaN,78 [],79 {},80 function(){}81 ];82 for ( var i = 0; i < values.length; i++ ) {83 expect( badValue( values[i] ) ).to.throw( TypeError );84 }85 function badValue( value ) {86 return function() {87 cp( './beep/boop', {88 'name': value89 });90 };91 }92 });93 it( 'should throw an error if provided a callback argument which is not a function', function test() {94 var values = [95 'beep',96 5,97 null,98 true,99 undefined,100 NaN,101 [],102 {}103 ];104 for ( var i = 0; i < values.length; i++ ) {105 expect( badValue( values[i] ) ).to.throw( TypeError );106 }107 function badValue( value ) {108 return function() {109 cp( './beep/boop', {}, value );110 };111 }112 });113 it( 'should create a file in a specified directory', function test( done ) {114 var dirpath;115 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );116 mkdirp.sync( dirpath );117 cp( dirpath, onFinish );118 function onFinish( error ) {119 var bool;120 if ( error ) {121 assert.ok( false );122 } else {123 bool = fs.existsSync( path.join( dirpath, 'index.js' ) );124 assert.isTrue( bool );125 }126 done();127 }128 });129 it( 'should create a configured file in a specified directory', function test( done ) {130 var dirpath;131 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );132 mkdirp.sync( dirpath );133 cp( dirpath, {134 'template': 'default',135 'filename': 'foo.js',136 'name': 'beepBoop',137 'desc': 'Returns a beep boop.'138 }, onFinish );139 function onFinish( error ) {140 var fpath1,141 fpath2,142 f1, f2;143 if ( error ) {144 assert.ok( false );145 done();146 return;147 }148 fpath1 = path.join( dirpath, 'foo.js' );149 fpath2 = path.join( __dirname, 'fixtures', 'foo.js' );150 f1 = fs.readFileSync( fpath1, {151 'encoding': 'utf8'152 });153 f2 = fs.readFileSync( fpath2, {154 'encoding': 'utf8'155 });156 assert.deepEqual( f1, f2 );157 done();158 }159 });160 it( 'should pass any read errors to a provided callback', function test( done ) {161 var dirpath,162 cp;163 cp = proxyquire( mpath, {164 'fs': {165 'readFile': function read( path, opts, clbk ) {166 clbk( new Error() );167 }168 }169 });170 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );171 cp( dirpath, onFinish );172 function onFinish( error ) {173 if ( error ) {174 assert.ok( true );175 } else {176 assert.ok( false );177 }178 done();179 }180 });181 it( 'should pass any write errors to a provided callback', function test( done ) {182 var dirpath;183 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );184 cp( dirpath, onFinish );185 function onFinish( error ) {186 if ( error ) {187 assert.ok( true );188 } else {189 assert.ok( false );190 }191 done();192 }193 });194 it( 'should create a file in a specified directory without requiring a callback', function test( done ) {195 var dirpath;196 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );197 mkdirp.sync( dirpath );198 cp( dirpath );199 setTimeout( onTimeout, 500 );200 function onTimeout() {201 var bool = fs.existsSync( path.join( dirpath, 'index.js' ) );202 assert.isTrue( bool );203 done();204 }205 });206 it( 'should create a file using a specified template', function test( done ) {207 var dirpath;208 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );209 mkdirp.sync( dirpath );210 cp( dirpath, {211 'template': 'default'212 }, onFinish );213 function onFinish( error ) {214 var bool;215 if ( error ) {216 assert.ok( false );217 } else {218 bool = fs.existsSync( path.join( dirpath, 'index.js' ) );219 assert.isTrue( bool );220 }221 done();222 }223 });224 it( 'should ignore any unrecognized options', function test( done ) {225 var dirpath;226 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );227 mkdirp.sync( dirpath );228 cp( dirpath, {229 'beep': 'boop'230 }, onFinish );231 function onFinish( error ) {232 var bool;233 if ( error ) {234 assert.ok( false );235 } else {236 bool = fs.existsSync( path.join( dirpath, 'index.js' ) );237 assert.isTrue( bool );238 }239 done();240 }241 });...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

1import path from "path";2import fs from "fs";3import freeSwagger from "../src/main";4const assertFiles = async (dirPath, apiFilesList,exactlyEqual = true) => {5 const filesPath = fs.readdirSync(dirPath);6 // 只要文件夹中包含改文件名就可以,不需要完全相符7 if(exactlyEqual){8 apiFilesList.forEach(filePath => {9 expect(filesPath.includes(filePath)).toBe(true);10 })11 }else{12 expect(filesPath).toEqual(apiFilesList);13 }14 filesPath.forEach(filename => {15 if(filename === 'interface'){16 const file = fs.readFileSync(path.resolve(dirPath, filename,'index.ts'), "utf-8");17 expect(file).toMatchSnapshot();18 return19 }20 if(filename === 'typedef'){21 const file = fs.readFileSync(path.resolve(dirPath, filename,'index.js'), "utf-8");22 expect(file).toMatchSnapshot();23 return24 }25 const file = fs.readFileSync(path.resolve(dirPath, filename), "utf-8");26 expect(file).toMatchSnapshot();27 });28};29describe("api test", () => {30 beforeAll(() => {31 Date.now = jest.fn(() => 1482363367071);32 global.__DEV__ = true33 });34 test("base option", async () => {35 const dirname = "swaggerPetstore";36 const dirPath = path.resolve(__dirname, "api", dirname);37 await freeSwagger({38 source: require(`./json/${dirname}`),39 root: dirPath,40 });41 await assertFiles(dirPath, ["pet.js", "store.js", "user.js"]);42 });43 test("simple jsdoc", async () => {44 const dirname = "swaggerPetstore";45 const dirPath = path.resolve(__dirname, "api",dirname + "1");46 await freeSwagger({47 source: require(`./json/${dirname}`),48 root: dirPath,49 jsDoc:true50 });51 await assertFiles(dirPath, ["pet.js", "store.js","typedef", "user.js"]);52 });53 test("ts language", async () => {54 const dirname = "uberApi";55 const dirPath = path.resolve(__dirname, "api", dirname);56 await freeSwagger({57 source: require(`./json/${dirname}`),58 lang: "ts",59 root: dirPath,60 });61 await assertFiles(dirPath, [62 "auditLog.ts",63 "device.ts",64 "interface",65 "mappers.ts",66 "ymTicketTypical.ts"67 ]);68 });69 test("custom ts template", async () => {70 const dirname = "homeIotApi";71 const dirPath = path.resolve(__dirname, "api", dirname);72 await freeSwagger({73 source: require(`./json/${dirname}`),74 root: dirPath,75 lang: "ts",76 header: `import { AxiosResponse } from 'axios'77import http from 'http'78`,79 });80 await assertFiles(dirPath, [81 "device.ts",82 "environment.ts",83 "interface",84 "zWave.ts",85 "zones.ts"86 ]);87 });88 test("should work with only one string params", async () => {89 global.__PATH__ = path.resolve(__dirname, "api/defaultString")90 const dirname = "swaggerPetstore1";91 await freeSwagger(path.resolve(__dirname, "json", `${dirname}.json`));92 await assertFiles(93 global.__PATH__ ,94 ["pet.js", "store.js", "user.js"],95 true96 );97 global.__PATH__ = ''98 });99 test("error params", async () => {100 try {101 await freeSwagger("/a/b/c")102 } catch (e) {103 expect(e.message).toBe("swagger 文档不规范,请检查参数格式")104 }105 });106 test("should work in openApi3", async () => {107 const dirPath = path.resolve(__dirname, `api`,'openApi3')108 await freeSwagger({source: path.resolve(__dirname, "json", 'openApi3'),root: dirPath });109 await assertFiles(dirPath, [110 "device.js",111 "environment.js",112 "zones.js",113 "zWave.js"114 ]);115 });116 test("should work with only one json params", async () => {117 global.__PATH__ = path.resolve(__dirname, "api/defaultJson")118 const dirname = "uberApi1";119 await freeSwagger(require(path.resolve(__dirname, "json", `${dirname}.json`)));120 await assertFiles(global.__PATH__, [121 "auditLog.js",122 "device.js",123 "mappers.js",124 "ymTicketTypical.js"125 ],true);126 global.__PATH__ = ''127 });128 test("type only", async () => {129 const dirname = "uberApi1";130 const dirPath = path.resolve(__dirname, "api", dirname + "TypeOnly")131 await freeSwagger({132 source: require(`./json/${dirname}`),133 root:dirPath ,134 typeOnly: true,135 jsDoc: true136 });137 const file = fs.readFileSync(path.resolve(dirPath,'typedef/index.js'), "utf-8");138 expect(file).toMatchSnapshot();139 });...

Full Screen

Full Screen

test.sync.js

Source:test.sync.js Github

copy

Full Screen

1/* global require, describe, it */2'use strict';3// MODULES //4var chai = require( 'chai' ),5 mkdirp = require( 'mkdirp' ),6 path = require( 'path' ),7 fs = require( 'fs' ),8 cp = require( './../lib/sync.js' );9// VARIABLES //10var expect = chai.expect,11 assert = chai.assert;12// TESTS //13describe( 'sync', function tests() {14 it( 'should export a function', function test() {15 expect( cp ).to.be.a( 'function' );16 });17 it( 'should throw an error if not provided a valid destination directory', function test() {18 var values = [19 5,20 null,21 true,22 undefined,23 NaN,24 [],25 {},26 function(){}27 ];28 for ( var i = 0; i < values.length; i++ ) {29 expect( badValue( values[i] ) ).to.throw( TypeError );30 }31 function badValue( value ) {32 return function() {33 cp( value );34 };35 }36 });37 it( 'should throw an error if provided an invalid options argument', function test() {38 var values = [39 'beep',40 5,41 null,42 true,43 undefined,44 NaN,45 [],46 function(){}47 ];48 for ( var i = 0; i < values.length; i++ ) {49 expect( badValue( values[i] ) ).to.throw( TypeError );50 }51 function badValue( value ) {52 return function() {53 cp( 'beep/boop', value );54 };55 }56 });57 it( 'should create a file in a specified directory', function test() {58 var dirpath,59 bool;60 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );61 mkdirp.sync( dirpath );62 cp( dirpath );63 bool = fs.existsSync( path.join( dirpath, 'index.js' ) );64 assert.isTrue( bool );65 });66 it( 'should create a configured file in a specified directory', function test() {67 var dirpath,68 fpath1,69 fpath2,70 f1, f2;71 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );72 mkdirp.sync( dirpath );73 cp( dirpath, {74 'template': 'default',75 'filename': 'foo.js',76 'name': 'beepBoop',77 'desc': 'Returns a beep boop.'78 });79 fpath1 = path.join( dirpath, 'foo.js' );80 fpath2 = path.join( __dirname, 'fixtures', 'foo.js' );81 f1 = fs.readFileSync( fpath1, {82 'encoding': 'utf8'83 });84 f2 = fs.readFileSync( fpath2, {85 'encoding': 'utf8'86 });87 assert.deepEqual( f1, f2 );88 });89 it( 'should create a file using a specified template', function test() {90 var dirpath,91 bool;92 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );93 mkdirp.sync( dirpath );94 cp( dirpath, {95 'template': 'default'96 });97 bool = fs.existsSync( path.join( dirpath, 'index.js' ) );98 assert.isTrue( bool );99 });100 it( 'should ignore any unrecognized options', function test() {101 var dirpath,102 bool;103 dirpath = path.resolve( __dirname, '../build/' + new Date().getTime() );104 mkdirp.sync( dirpath );105 cp( dirpath, {106 'beep': 'boop'107 });108 bool = fs.existsSync( path.join( dirpath, 'index.js' ) );109 assert.isTrue( bool );110 });...

Full Screen

Full Screen

view.js

Source:view.js Github

copy

Full Screen

1// communcation with file system with the nodejs module called fs2// google specific use case to identify what module to use3let fs = require("fs"); // importing fs module4let path = require("path");5function isFileChecker(dirPath){ // Checking if the content in dirPath is a file or not6 return fs.lstatSync(dirPath).isFile(); // Google this function of fs7}8function readContent(dirPath){ // Read the dir given by dirPath9 return fs.readdirSync(dirPath);10}11function viewTree(dirPath, indent){12 // dirPath can either be file or a folder(directory)13 // check if dirPath is a file14 if(isFileChecker(dirPath)){15 console.log(indent,path.basename(dirPath) + "*"); // if file then print its name16 } else{17 // directory hai phir ye kyuki file ni hai18 // print dirPath19 console.log(indent, path.basename(dirPath));20 // read children of the current directory21 let childrens = readContent(dirPath);22 // for each child call the viewFlat (recursive call)23 for(let i = 0; i < childrens.length; i++){24 viewTree(path.join(dirPath, childrens[i]), indent+"\t");25 }26 }27}28function viewFlat(dirPath){29 // dirPath can either be file or a folder(directory)30 // check if dirPath is a file31 if(isFileChecker(dirPath)){32 console.log(dirPath + "*"); // if file then print its name33 } else{34 // directory hai phir ye kyuki file ni hai35 // print dirPath36 console.log(dirPath);37 // read children of the current directory38 let childrens = readContent(dirPath);39 // for each child call the viewFlat (recursive call)40 for(let i = 0; i < childrens.length; i++){41 viewFlat(dirPath + "/" + childrens[i]);42 }43 }44}45function viewFnToExport(dirPath, mode){46 if(mode === 'tree'){47 viewTree(dirPath, "");48 }49 else if(mode === 'flat'){50 viewFlat(dirPath);51 }52 else{53 console.log("Wrong mode entered!");54 }55}56module.exports = {57 viewFn : viewFnToExport...

Full Screen

Full Screen

nodeutils.js

Source:nodeutils.js Github

copy

Full Screen

1var async = require("async");2var fs = require("fs");3var path = require("path");4var utils = require("ripple-lib").utils;5// Empty a directory.6// done(err) : err = true if an error occured.7var emptyPath = function(dirPath, done) {8 fs.readdir(dirPath, function(err, files) {9 if (err) {10 done(err);11 }12 else {13 async.some(files.map(function(f) { return path.join(dirPath, f); }), rmPath, done);14 }15 });16};17// Make a directory and sub-directories.18var mkPath = function(dirPath, mode, done) {19 fs.mkdir(dirPath, typeof mode === "string" ? parseInt(mode, 8) : mode, function(e) {20 if (!e || e.code === "EEXIST") {21 // Created or already exists, done.22 done();23 }24 else if (e.code === "ENOENT") {25 // Missing sub dir.26 mkPath(path.dirname(dirPath), mode, function(e) {27 if (e) {28 throw e;29 }30 else {31 mkPath(dirPath, mode, done);32 }33 });34 }35 else {36 throw e;37 }38 });39};40// Create directory if needed and empty if needed.41var resetPath = function(dirPath, mode, done) {42 mkPath(dirPath, mode, function(e) {43 if (e) {44 done(e);45 }46 else {47 emptyPath(dirPath, done);48 }49 });50};51// Remove path recursively.52// done(err)53var rmPath = function(dirPath, done) {54// console.log("rmPath: %s", dirPath);55 fs.lstat(dirPath, function(err, stats) {56 if (err && err.code == "ENOENT") {57 done();58 }59 if (err) {60 done(err);61 }62 else if (stats.isDirectory()) {63 emptyPath(dirPath, function(e) {64 if (e) {65 done(e);66 }67 else {68// console.log("rmdir: %s", dirPath); done();69 fs.rmdir(dirPath, done);70 }71 });72 }73 else {74// console.log("unlink: %s", dirPath); done();75 fs.unlink(dirPath, done);76 }77 });78};79exports.mkPath = mkPath;80exports.resetPath = resetPath;81exports.rmPath = rmPath;...

Full Screen

Full Screen

organize.js

Source:organize.js Github

copy

Full Screen

1let fs = require("fs");2let path = require("path");3let types = {4 media: ["mp4", "mkv", "mp3"],5 archives: ['zip', '7z', 'rar', 'tar', 'gz', 'ar', 'iso', "xz"],6 documents: ['docx', 'doc', 'pdf', 'xlsx', 'xls', 'odt', 'ods', 'odp', 'odg', 'odf', 'txt', 'ps', 'tex'],7 app: ['exe', 'dmg', 'pkg', "deb"]8}9function isFileOrNot(dirPath){10 return fs.lstatSync(dirPath).isFile();11}12function readContent(dirPath){ // Read the dir given by dirPath13 return fs.readdirSync(dirPath);14}15function dirCreator(dirPath){16 if (fs.existsSync(dirPath) == false){17 fs.mkdirSync(dirPath);18 }19}20function getDirectoryName(dirPath){21 let strArr = dirPath.split('.');22 let ext = strArr.pop();23 for(let key in types){24 for(let i = 0; i < types[key].length; i++){25 if(types[key][i] == ext){26 return key;27 }28 }29 }30 return 'others';31}32function OrganizeDir(dirPath)33{34 let isFile = isFileOrNot(dirPath);35 if(isFile){36 let folderName = getDirectoryName(dirPath);37 console.log(dirPath, "->", folderName);38 fs.copyFileSync(dirPath, path.join(orgFilePath, folderName, path.basename(dirPath)));39 }40 else{41 let content = readContent(dirPath);42 for(let i = 0; i < content.length; i++){43 let childPath = path.join(dirPath, content[i]);44 organizeDir(childPath);45 }46 }47}48function OrganizeFnToExport(dirPath){49 let orgFilePath = path.join(dirPath, "Organized");50 dirCreator(orgFilePath);51 for(let key in types){52 let innerDirPath = path.join(orgFilePath, key);53 dirCreator(innerDirPath);54 }55 // others56 let othersDirPath = path.join(orgFilePath , 'others');57 dirCreator(othersDirPath);58 OrganizeDir(dirPath);59}60module.exports = {61 organizeFn : OrganizeFnToExport...

Full Screen

Full Screen

mkpath.js

Source:mkpath.js Github

copy

Full Screen

1var fs = require('fs');2var path = require('path');3var mkpath = function mkpath(dirpath, mode, callback) {4 dirpath = path.resolve(dirpath);5 6 if (typeof mode === 'function' || typeof mode === 'undefined') {7 callback = mode;8 mode = 0777 & (~process.umask());9 }10 11 if (!callback) {12 callback = function () {};13 }14 15 fs.stat(dirpath, function (err, stats) {16 if (err) {17 if (err.code === 'ENOENT') {18 mkpath(path.dirname(dirpath), mode, function (err) {19 if (err) {20 callback(err);21 } else {22 fs.mkdir(dirpath, mode, callback);23 }24 });25 } else {26 callback(err);27 }28 } else if (stats.isDirectory()) {29 callback(null);30 } else {31 callback(new Error(dirpath + ' exists and is not a directory'));32 }33 });34};35mkpath.sync = function mkpathsync(dirpath, mode) {36 dirpath = path.resolve(dirpath);37 38 if (typeof mode === 'undefined') {39 mode = 0777 & (~process.umask());40 }41 42 try {43 if (!fs.statSync(dirpath).isDirectory()) {44 throw new Error(dirpath + ' exists and is not a directory');45 }46 } catch (err) {47 if (err.code === 'ENOENT') {48 mkpathsync(path.dirname(dirpath), mode);49 fs.mkdirSync(dirpath, mode);50 } else {51 throw err;52 }53 }54};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch({ headless: false });5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.screenshot({ path: path.join(await page.dirPath(), 'example.png') });8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test, expect } = require('@playwright/test');2const path = require('path');3const fs = require('fs');4test('Test', async ({ browser }) => {5 const context = await browser.newContext({6 recordVideo: {7 dir: path.join(__dirname, 'videos'),8 },9 });10 const page = await context.newPage();11 expect(await page.screenshot()).toMatchSnapshot('home-page.png');12 await page.click('text=Docs');13 expect(await page.screenshot()).toMatchSnapshot('docs-page.png');14 await context.close();15 const videoDir = await context.dirPath();16 const videoFiles = fs.readdirSync(videoDir);17 expect(videoFiles.length).toBe(1);18 expect(videoFiles[0]).toBe('recording.mp4');19});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { dirPath } = require('playwright/lib/utils/utils');2const path = require('path');3const assert = require('assert');4const dir = dirPath(path.join('test', 'data'));5assert.equal(dir, 'test/data');6const dir = dirPath(path.join('test', 'data'));7assert.equal(dir, 'test/data');8const dir = dirPath(path.join('test', 'data'));9assert.equal(dir, 'test/data');10const { dirPath } = require('playwright/lib/utils/utils');11const path = require('path');12const dir = dirPath(path.join('test', 'data'));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { dirPath } = require('playwright/lib/server/utils');2const path = require('path');3console.log(dirPath(path.join(__dirname, 'test.js')));4const path = require('path');5console.log(path.relative(__dirname, 'test.js'));6const path = require('path');7console.log(path.dirname('test.js'));8const path = require('path');9console.log(path.parse('test.js').dir);10const path = require('path');11console.log(path.sep);12const path = require('path');13console.log(path.join(__dirname, 'test.js'));14const path = require('path');15console.log(path.resolve(__dirname, 'test.js'));16const path = require('path');17console.log(path.posix.join(__dirname, 'test.js'));18const path = require('path');19console.log(path.win32.join(__dirname, 'test.js'));20const path = require('path');21console.log(path.format({22}));

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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