Best JavaScript code snippet using cypress
async.js
Source:async.js
...40 });41 nodeGte8("called asynchronously", async () => {42 process.chdir("config-file-async-function");43 await expect(44 babel.transformAsync(""),45 ).rejects.toThrowErrorMatchingInlineSnapshot(46 `"You appear to be using an async configuration, which your current version of Babel does` +47 ` not support. We may add support for this in the future, but if you're on the most recent` +48 ` version of @babel/core and still seeing this error, then you'll need to synchronously` +49 ` return your config."`,50 );51 });52 });53 describe("promise", () => {54 it("called synchronously", () => {55 process.chdir("config-file-promise");56 expect(() =>57 babel.transformSync(""),58 ).toThrowErrorMatchingInlineSnapshot(59 `"You appear to be using an async configuration, which your current version of Babel does` +60 ` not support. We may add support for this in the future, but if you're on the most recent` +61 ` version of @babel/core and still seeing this error, then you'll need to synchronously` +62 ` return your config."`,63 );64 });65 it("called asynchronously", async () => {66 process.chdir("config-file-promise");67 await expect(68 babel.transformAsync(""),69 ).rejects.toThrowErrorMatchingInlineSnapshot(70 `"You appear to be using an async configuration, which your current version of Babel does` +71 ` not support. We may add support for this in the future, but if you're on the most recent` +72 ` version of @babel/core and still seeing this error, then you'll need to synchronously` +73 ` return your config."`,74 );75 });76 });77 describe("cache.using", () => {78 nodeGte8("called synchronously", () => {79 process.chdir("config-cache");80 expect(() =>81 babel.transformSync(""),82 ).toThrowErrorMatchingInlineSnapshot(83 `"You appear to be using an async cache handler, which your current version of Babel does` +84 ` not support. We may add support for this in the future, but if you're on the most recent` +85 ` version of @babel/core and still seeing this error, then you'll need to synchronously` +86 ` handle your caching logic."`,87 );88 });89 nodeGte8("called asynchronously", async () => {90 process.chdir("config-cache");91 await expect(92 babel.transformAsync(""),93 ).rejects.toThrowErrorMatchingInlineSnapshot(94 `"You appear to be using an async cache handler, which your current version of Babel does` +95 ` not support. We may add support for this in the future, but if you're on the most recent` +96 ` version of @babel/core and still seeing this error, then you'll need to synchronously` +97 ` handle your caching logic."`,98 );99 });100 });101 });102 describe("plugin", () => {103 describe("factory function", () => {104 nodeGte8("called synchronously", () => {105 process.chdir("plugin");106 expect(() => babel.transformSync("")).toThrow(107 `[BABEL] unknown: You appear to be using an async plugin/preset, but Babel` +108 ` has been called synchronously`,109 );110 });111 nodeGte8("called asynchronously", async () => {112 process.chdir("plugin");113 await expect(babel.transformAsync("")).resolves.toMatchObject({114 code: `"success"`,115 });116 });117 });118 describe(".pre", () => {119 nodeGte8("called synchronously", () => {120 process.chdir("plugin-pre");121 expect(() =>122 babel.transformSync(""),123 ).toThrowErrorMatchingInlineSnapshot(124 `"unknown: You appear to be using an plugin with an async .pre, which your current version` +125 ` of Babel does not support. If you're using a published plugin, you may need to upgrade your` +126 ` @babel/core version."`,127 );128 });129 nodeGte8("called asynchronously", async () => {130 process.chdir("plugin-pre");131 await expect(132 babel.transformAsync(""),133 ).rejects.toThrowErrorMatchingInlineSnapshot(134 `"unknown: You appear to be using an plugin with an async .pre, which your current version` +135 ` of Babel does not support. If you're using a published plugin, you may need to upgrade your` +136 ` @babel/core version."`,137 );138 });139 });140 describe(".post", () => {141 nodeGte8("called synchronously", () => {142 process.chdir("plugin-post");143 expect(() =>144 babel.transformSync(""),145 ).toThrowErrorMatchingInlineSnapshot(146 `"unknown: You appear to be using an plugin with an async .post, which your current version` +147 ` of Babel does not support. If you're using a published plugin, you may need to upgrade your` +148 ` @babel/core version."`,149 );150 });151 nodeGte8("called asynchronously", async () => {152 process.chdir("plugin-post");153 await expect(154 babel.transformAsync(""),155 ).rejects.toThrowErrorMatchingInlineSnapshot(156 `"unknown: You appear to be using an plugin with an async .post, which your current version` +157 ` of Babel does not support. If you're using a published plugin, you may need to upgrade your` +158 ` @babel/core version."`,159 );160 });161 });162 describe("inherits", () => {163 nodeGte8("called synchronously", () => {164 process.chdir("plugin-inherits");165 expect(() => babel.transformSync("")).toThrow(166 `[BABEL] unknown: You appear to be using an async plugin/preset, but Babel has been` +167 ` called synchronously`,168 );169 });170 nodeGte8("called asynchronously", async () => {171 process.chdir("plugin-inherits");172 await expect(babel.transformAsync("")).resolves.toMatchObject({173 code: `"success 2"\n"success"`,174 });175 });176 });177 (supportsESM ? describe : describe.skip)(".mjs files", () => {178 it("called synchronously", async () => {179 process.chdir("plugin-mjs-native");180 await expect(spawnTransformSync()).rejects.toThrow(181 `[BABEL]: You appear to be using a native ECMAScript module plugin, which is` +182 ` only supported when running Babel asynchronously.`,183 );184 });185 it("called asynchronously", async () => {186 process.chdir("plugin-mjs-native");187 await expect(spawnTransformAsync()).resolves.toMatchObject({188 code: `"success"`,189 });190 });191 });192 });193 describe("preset", () => {194 describe("factory function", () => {195 nodeGte8("called synchronously", () => {196 process.chdir("preset");197 expect(() => babel.transformSync("")).toThrow(198 `[BABEL] unknown: You appear to be using an async plugin/preset, ` +199 `but Babel has been called synchronously`,200 );201 });202 nodeGte8("called asynchronously", async () => {203 process.chdir("preset");204 await expect(babel.transformAsync("")).resolves.toMatchObject({205 code: `"success"`,206 });207 });208 });209 describe("plugins", () => {210 nodeGte8("called synchronously", () => {211 process.chdir("preset-plugin-promise");212 expect(() => babel.transformSync("")).toThrow(213 `[BABEL] unknown: You appear to be using a promise as a plugin, which your` +214 ` current version of Babel does not support. If you're using a published` +215 ` plugin, you may need to upgrade your @babel/core version. As an` +216 ` alternative, you can prefix the promise with "await".`,217 );218 });219 nodeGte8("called asynchronously", async () => {220 process.chdir("preset-plugin-promise");221 await expect(babel.transformAsync("")).rejects.toThrow(222 `[BABEL] unknown: You appear to be using a promise as a plugin, which your` +223 ` current version of Babel does not support. If you're using a published` +224 ` plugin, you may need to upgrade your @babel/core version. As an` +225 ` alternative, you can prefix the promise with "await".`,226 );227 });228 });229 (supportsESM ? describe : describe.skip)(".mjs files", () => {230 it("called synchronously", async () => {231 process.chdir("preset-mjs-native");232 await expect(spawnTransformSync()).rejects.toThrow(233 `[BABEL]: You appear to be using a native ECMAScript module preset, which is` +234 ` only supported when running Babel asynchronously.`,235 );...
index.js
Source:index.js
...21 </div>22 )23 } 24 `25 const transformed = (await babel.transformAsync(input, {26 plugins: ['@babel/plugin-syntax-jsx', plugin],27 filename: 'test/index.js',28 })).code29 expect(format(transformed)).to.equal(30 format(`31 function MyComponent() {32 return (33 <div className="foo" data-source-loc="test/index.js:4:8">34 <Alert variant="danger" data-source-loc="test/index.js:5:10">35 {names.map(name =>36 <Card key={name} data-source-loc="test/index.js:7:14">37 {name}38 </Card>39 )}40 </Alert>41 </div>42 )43 } 44 `)45 )46})47it(`ignores React.Fragment from import * as React from 'react'`, async () => {48 const input = `49 import * as React from 'react'50 function MyComponent() {51 return (52 <React.Fragment>53 <Alert variant="danger">54 {names.map(name =>55 <Card key={name}>56 {name}57 </Card>58 )}59 </Alert>60 </React.Fragment>61 )62 } 63 `64 const transformed = (await babel.transformAsync(input, {65 plugins: ['@babel/plugin-syntax-jsx', plugin],66 filename: 'test/index.js',67 })).code68 expect(format(transformed)).to.equal(69 format(`70 import * as React from 'react'71 function MyComponent() {72 return (73 <React.Fragment>74 <Alert variant="danger" data-source-loc="test/index.js:6:10">75 {names.map(name =>76 <Card key={name} data-source-loc="test/index.js:8:14">77 {name}78 </Card>79 )}80 </Alert>81 </React.Fragment>82 )83 } 84 `)85 )86})87it(`ignores React.Fragment from import React from 'react'`, async () => {88 const input = `89 import React from 'react'90 function MyComponent() {91 return (92 <React.Fragment>93 <Alert variant="danger">94 {names.map(name =>95 <Card key={name}>96 {name}97 </Card>98 )}99 </Alert>100 </React.Fragment>101 )102 } 103 `104 const transformed = (await babel.transformAsync(input, {105 plugins: ['@babel/plugin-syntax-jsx', plugin],106 filename: 'test/index.js',107 })).code108 expect(format(transformed)).to.equal(109 format(`110 import React from 'react'111 function MyComponent() {112 return (113 <React.Fragment>114 <Alert variant="danger" data-source-loc="test/index.js:6:10">115 {names.map(name =>116 <Card key={name} data-source-loc="test/index.js:8:14">117 {name}118 </Card>119 )}120 </Alert>121 </React.Fragment>122 )123 } 124 `)125 )126})127it(`ignores Fragment from import { Fragment } from 'react'`, async () => {128 const input = `129 import React, {Fragment} from 'react'130 function MyComponent() {131 return (132 <Fragment>133 <Alert variant="danger">134 {names.map(name =>135 <Card key={name}>136 {name}137 </Card>138 )}139 </Alert>140 </Fragment>141 )142 } 143 `144 const transformed = (await babel.transformAsync(input, {145 plugins: ['@babel/plugin-syntax-jsx', plugin],146 filename: 'test/index.js',147 })).code148 expect(format(transformed)).to.equal(149 format(`150 import React, {Fragment} from 'react'151 function MyComponent() {152 return (153 <Fragment>154 <Alert variant="danger" data-source-loc="test/index.js:6:10">155 {names.map(name =>156 <Card key={name} data-source-loc="test/index.js:8:14">157 {name}158 </Card>159 )}160 </Alert>161 </Fragment>162 )163 } 164 `)165 )166})167it(`ignores React.Fragment from const React = require('react')`, async () => {168 const input = `169 const React = require('react')170 function MyComponent() {171 return (172 <React.Fragment>173 <Alert variant="danger">174 {names.map(name =>175 <Card key={name}>176 {name}177 </Card>178 )}179 </Alert>180 </React.Fragment>181 )182 } 183 `184 const transformed = (await babel.transformAsync(input, {185 plugins: ['@babel/plugin-syntax-jsx', plugin],186 filename: 'test/index.js',187 })).code188 expect(format(transformed)).to.equal(189 format(`190 const React = require('react')191 function MyComponent() {192 return (193 <React.Fragment>194 <Alert variant="danger" data-source-loc="test/index.js:6:10">195 {names.map(name =>196 <Card key={name} data-source-loc="test/index.js:8:14">197 {name}198 </Card>199 )}200 </Alert>201 </React.Fragment>202 )203 } 204 `)205 )206})207it(`ignores Fragment from const {Fragment} = require('react')`, async () => {208 const input = `209 const {Fragment} = require('react')210 function MyComponent() {211 return (212 <Fragment>213 <Alert variant="danger">214 {names.map(name =>215 <Card key={name}>216 {name}217 </Card>218 )}219 </Alert>220 </Fragment>221 )222 } 223 `224 const transformed = (await babel.transformAsync(input, {225 plugins: ['@babel/plugin-syntax-jsx', plugin],226 filename: 'test/index.js',227 })).code228 expect(format(transformed)).to.equal(229 format(`230 const {Fragment} = require('react')231 function MyComponent() {232 return (233 <Fragment>234 <Alert variant="danger" data-source-loc="test/index.js:6:10">235 {names.map(name =>236 <Card key={name} data-source-loc="test/index.js:8:14">237 {name}238 </Card>...
replace-visitor-single.test.js
Source:replace-visitor-single.test.js
1import * as Babel from '@babel/core'2import Test from 'ava'3import { ReplaceVisitorInvalidImportTypeError } from '../../../library/replace/error/replace-visitor-invalid-import-type-error.js'4Test.beforeEach((test) => {5 test.context.codeIn = 'console.log(__require.resolve(\'./index.js\'))'6 test.context.option = { 7 'plugins': [ 8 [9 require.resolve('../../../index.js'),10 {11 'rule': [12 {13 'searchFor': '__require',14 'replaceWith': '...',15 'parserOption': { 16 'plugins': [ 'importMeta' ], 17 'sourceType': 'module' 18 },19 'addImport': []20 }21 ]22 } 23 ]24 ]25 }26 27})28Test('rule.replaceWith = \'createRequire(import.meta.url)\'', async (test) => {29 test.context.option.plugins[0][1].rule[0].replaceWith = 'createRequire(import.meta.url)'30 let { code: actualCodeOut } = await Babel.transformAsync(test.context.codeIn, test.context.option)31 let expectedCodeOut = 'console.log(createRequire(import.meta.url).resolve(\'./index.js\'));'32 test.is(actualCodeOut, expectedCodeOut)33})34Test('addImport.type: \'default\'', async (test) => {35 test.context.option.plugins[0][1].rule[0].replaceWith = '__importIdentifier(import.meta.url)'36 test.context.option.plugins[0][1].rule[0].addImport.push({37 'type': 'default',38 'source': 'module',39 'option': {40 'nameHint': 'createRequire'41 }42 })43 let { code: actualCodeOut } = await Babel.transformAsync(test.context.codeIn, test.context.option)44 let expectedCodeOut = 'import _createRequire from "module";\nconsole.log(_createRequire(import.meta.url).resolve(\'./index.js\'));'45 test.is(actualCodeOut, expectedCodeOut)46})47Test('addImport.type: \'named\'', async (test) => {48 test.context.option.plugins[0][1].rule[0].replaceWith = '__importIdentifier(import.meta.url)'49 test.context.option.plugins[0][1].rule[0].addImport.push({50 'type': 'named',51 'name': 'createRequire',52 'source': 'module'53 })54 let { code: actualCodeOut } = await Babel.transformAsync(test.context.codeIn, test.context.option)55 let expectedCodeOut = 'import { createRequire as _createRequire } from "module";\nconsole.log(_createRequire(import.meta.url).resolve(\'./index.js\'));'56 test.is(actualCodeOut, expectedCodeOut)57})58Test('addImport.type: \'namespace\'', async (test) => {59 test.context.option.plugins[0][1].rule[0].replaceWith = '__importIdentifier(import.meta.url)'60 test.context.option.plugins[0][1].rule[0].addImport.push({61 'type': 'namespace',62 'source': 'module',63 'option': {64 'nameHint': 'createRequire'65 }66 })67 let { code: actualCodeOut } = await Babel.transformAsync(test.context.codeIn, test.context.option)68 let expectedCodeOut = 'import * as _createRequire from "module";\nconsole.log(_createRequire(import.meta.url).resolve(\'./index.js\'));'69 test.is(actualCodeOut, expectedCodeOut)70})71Test('addImport.type: \'sideEffect\'', async (test) => {72 test.context.option.plugins[0][1].rule[0].replaceWith = '__importIdentifier(import.meta.url)'73 test.context.option.plugins[0][1].rule[0].addImport.push({74 'type': 'sideEffect',75 'source': 'module'76 })77 let { code: actualCodeOut } = await Babel.transformAsync(test.context.codeIn, test.context.option)78 let expectedCodeOut = 'import "module";\nconsole.log(__importIdentifier(import.meta.url).resolve(\'./index.js\'));'79 test.is(actualCodeOut, expectedCodeOut)80})81Test('addImport.type: invalid', async (test) => {82 test.context.option.plugins[0][1].rule[0].replaceWith = '__importIdentifier(import.meta.url)'83 test.context.option.plugins[0][1].rule[0].addImport.push({84 'type': '_sideEffect',85 'source': 'module'86 })87 let promise = Babel.transformAsync(test.context.codeIn, test.context.option)88 await test.throwsAsync(promise, { 'instanceOf': ReplaceVisitorInvalidImportTypeError })...
index-add-import.test.js
Source:index-add-import.test.js
1import { createRequire as CreateRequire } from 'module'2import Babel from '@babel/core'3import Path from 'path'4import Test from 'ava'5import URL from 'url'6import { InvalidImportTypeError } from '../library/error/invalid-import-type-error.cjs'7const Require = CreateRequire(import.meta.url)8const SourceFilePath = URL.fileURLToPath(import.meta.url).replace('/release/', '/source/')9const SourceFolderPath = Path.dirname(SourceFilePath)10Test.beforeEach((test) => {11 test.context.codeIn = 'console.log(__42)'12 test.context.option = {13 'root': SourceFolderPath,14 'plugins': [15 [16 Require.resolve('@virtualpatterns/babel-plugin-mablung-replace-identifier'),17 {18 'rule': [19 {20 'searchFor': /__42/gi,21 'replaceWith': '42',22 'addImport': []23 }24 ]25 }26 ]27 ]28 }29})30Test('plugins: [ [ \'...\', { rule: [ addImport: default ] } ] ]', async (test) => {31 test.context.option.plugins[0][1].rule[0].addImport.push({32 'type': 'default',33 'source': 'url',34 'option': {35 'nameHint': 'URL'36 }37 })38 let { code: actualCodeOut } = await Babel.transformAsync(test.context.codeIn, test.context.option)39 let expectedCodeOut = 'import _URL from "url";\n' +40 'console.log(42);'41 // test.log(actualCodeOut)42 test.is(actualCodeOut, expectedCodeOut)43})44Test('plugins: [ [ \'...\', { rule: [ addImport: named ] } ] ]', async (test) => {45 test.context.option.plugins[0][1].rule[0].addImport.push({46 'type': 'named',47 'name': 'createRequire',48 'source': 'module'49 })50 let { code: actualCodeOut } = await Babel.transformAsync(test.context.codeIn, test.context.option)51 let expectedCodeOut = 'import { createRequire as _createRequire } from "module";\n' +52 'console.log(42);'53 // test.log(actualCodeOut)54 test.is(actualCodeOut, expectedCodeOut)55})56Test('plugins: [ [ \'...\', { rule: [ addImport: namespace ] } ] ]', async (test) => {57 test.context.option.plugins[0][1].rule[0].addImport.push({58 'type': 'namespace',59 'source': 'module',60 'option': {61 'nameHint': 'createRequire'62 }63 })64 let { code: actualCodeOut } = await Babel.transformAsync(test.context.codeIn, test.context.option)65 let expectedCodeOut = 'import * as _createRequire from "module";\n' +66 'console.log(42);'67 // test.log(actualCodeOut)68 test.is(actualCodeOut, expectedCodeOut)69})70Test('plugins: [ [ \'...\', { rule: [ addImport: sideEffect ] } ] ]', async (test) => {71 test.context.option.plugins[0][1].rule[0].addImport.push({72 'type': 'sideEffect',73 'source': 'module'74 })75 let { code: actualCodeOut } = await Babel.transformAsync(test.context.codeIn, test.context.option)76 let expectedCodeOut = 'import "module";\n' +77 'console.log(42);'78 // test.log(actualCodeOut)79 test.is(actualCodeOut, expectedCodeOut)80})81Test('plugins: [ [ \'...\', { rule: [ addImport: invalid ] } ] ]', async (test) => {82 test.context.option.plugins[0][1].rule[0].addImport.push({83 'type': '_sideEffect',84 'source': 'module'85 })86 await test.throwsAsync(Babel.transformAsync(test.context.codeIn, test.context.option), { 'instanceOf': InvalidImportTypeError })...
index.test.js
Source:index.test.js
1import { createRequire as CreateRequire } from 'module'2import Babel from '@babel/core'3import Path from 'path'4import Test from 'ava'5import URL from 'url'6const Require = CreateRequire(import.meta.url)7const SourceFilePath = URL.fileURLToPath(import.meta.url).replace('/release/', '/source/')8const SourceFolderPath = Path.dirname(SourceFilePath).replace('/release/', '/source/')9Test.beforeEach((test) => {10 test.context.option = { 11 'root': SourceFolderPath,12 'plugins': [13 [14 Require.resolve('@virtualpatterns/babel-plugin-mablung-replace-string-literal'),15 {16 'rule': [17 {18 'searchFor': /^(\.{1,2}\/.*?)\.js$/gi,19 'replaceWith': '$1.cjs'20 }21 ]22 } 23 ]24 ]25 }26 27})28Test('import', async (test) => {29 let codeIn = 'import { abc } from \'./abc.js\''30 let expectedCodeOut = 'import { abc } from "./abc.cjs";'31 let { code: actualCodeOut } = await Babel.transformAsync(codeIn, test.context.option)32 test.is(actualCodeOut, expectedCodeOut)33})34Test('import(...)', async (test) => {35 let codeIn = 'const abcPromise = import(\'./abc.js\')'36 let expectedCodeOut = 'const abcPromise = import("./abc.cjs");'37 let { code: actualCodeOut } = await Babel.transformAsync(codeIn, test.context.option)38 test.is(actualCodeOut, expectedCodeOut)39})40Test('require(...)', async (test) => {41 let codeIn = 'const abc = require(\'./abc.js\')'42 let expectedCodeOut = 'const abc = require("./abc.cjs");'43 let { code: actualCodeOut } = await Babel.transformAsync(codeIn, test.context.option)44 test.is(actualCodeOut, expectedCodeOut)45})46Test('let', async (test) => {47 let codeIn = 'let abc = \'./abc.js\''48 let expectedCodeOut = 'let abc = "./abc.cjs";'49 let { code: actualCodeOut } = await Babel.transformAsync(codeIn, test.context.option)50 test.is(actualCodeOut, expectedCodeOut)51})52Test('let ...', async (test) => {53 let codeIn = 'let abc = \'./ab\' + \'c.js\''54 let expectedCodeOut = 'let abc = \'./ab\' + \'c.js\';'55 let { code: actualCodeOut } = await Babel.transformAsync(codeIn, test.context.option)56 test.is(actualCodeOut, expectedCodeOut)57})58Test('console.log(...)', async (test) => {59 let codeIn = 'console.log(\'Here at ./abc.js and there at ./def.js\')'60 let expectedCodeOut = 'console.log(\'Here at ./abc.js and there at ./def.js\');'61 let { code: actualCodeOut } = await Babel.transformAsync(codeIn, test.context.option)62 test.is(actualCodeOut, expectedCodeOut)63})64Test('fs.readFileAsync(...)', async (test) => {65 let codeIn = 'fs.readFileAsync(\'./abc.json\')'66 let expectedCodeOut = 'fs.readFileAsync(\'./abc.json\');'67 let { code: actualCodeOut } = await Babel.transformAsync(codeIn, test.context.option)68 test.is(actualCodeOut, expectedCodeOut)...
test.mjs
Source:test.mjs
...4import dedent from 'dedent'5import babel from '@babel/core'6import { SourceMapConsumer } from 'source-map'7test('printing', async function () {8 const result = await babel.transformAsync(`9 function a() {return test }10 const test=a11 test( ''12 )13 `, { plugins: [prettier] })14 assert.equal(result.code, dedent`15 function a() {16 return test;17 }18 const test = a;19 test("");20 ` + '\n')21})22test('generatorOpts', async function () {23 const result = await babel.transformAsync(`24 function a() {return test }25 const test=a26 test( ''27 )28 `, {29 plugins: [prettier],30 generatorOpts: {31 semi: false,32 singleQuote: true33 }34 })35 assert.equal(result.code, dedent`36 function a() {37 return test38 }39 const test = a40 test('')41 ` + '\n')42})43test('comments', async function () {44 const result = await babel.transformAsync(`45 whatever(46 // test47 'a long string and some arguments', 'that will hopefully cause prettier to wrap this',48 /* har har */ { oh: 'em', gee }49 )50 `, { plugins: [prettier] })51 assert.equal(result.code, dedent`52 whatever(53 // test54 "a long string and some arguments",55 "that will hopefully cause prettier to wrap this",56 /* har har */ { oh: "em", gee }57 );58 ` + '\n')59})60test('source maps', async function () {61 const result = await babel.transformAsync(dedent`62 function a() {return test }63 const test=a64 test( ''65 )66 `, {67 sourceMaps: true,68 plugins: [69 ['minify-mangle-names', { topLevel: true }],70 prettier71 ]72 })73 assert.equal(result.code, dedent`74 function b() {75 return a;...
premix-transform.js
Source:premix-transform.js
...8 { filter: /(\/app\/pages\/|\\app\\pages\\)(.*)\.(tsx|jsx|js)$/ },9 async args => {10 const contents = fs.readFileSync(args.path, 'utf8');11 try {12 const transformOne = await babel.transformAsync(contents, {13 filename: args.path,14 presets: ['@babel/preset-typescript'],15 plugins: ['./src/babel/transform'],16 });17 const transformTwo = await babel.transformAsync(transformOne.code, {18 filename: args.path,19 presets: ['@babel/preset-typescript'],20 plugins: ['babel-plugin-remove-unused-import'],21 });22 return {23 contents: transformTwo.code,24 loader: 'jsx',25 };26 } catch (error) {27 console.log(error);28 }29 }30 );31 },...
core.js
Source:core.js
2const code = `3o.a ??= 34`5function f1() {6 babel.transformAsync(code, {7 plugins: ["@babel/plugin-proposal-logical-assignment-operators"],8 }).then(o => {9 console.log(o)10 })11}12function f2() {13 babel.transformAsync('const n:number = 3', {14 presets: ["@babel/preset-typescript"],15 filename: 'index.ts'16 }).then(o => {17 console.log(o)18 })19}...
Using AI Code Generation
1const babel = require('@babel/core');2module.exports = (on, config) => {3 on('task', {4 async babelTransformAsync(code) {5 const result = await babel.transformAsync(code, {6 });7 return result.code;8 },9 });10};11describe('babel transform async', () => {12 it('should transform async code', () => {13 cy.task('babelTransformAsync', 'async () => {}').then((result) => {14 expect(result).to.equal('async function () {}');15 });16 });17});18describe('babel transform async', () => {19 it('should transform async code', () => {20 cy.task('babelTransform', 'async () => {}').then((result) => {21 expect(result).to.equal('async function () {}');22 });23 });24});
Using AI Code Generation
1const babel = require('babel-core')2const fs = require('fs')3const path = require('path')4const { promisify } = require('util')5const readFile = promisify(fs.readFile)6const writeFile = promisify(fs.writeFile)7const getJsPath = (filePath) => {8 return filePath.replace('.coffee', '.js')9}10const getJsPathFromTest = (filePath) => {11 return filePath.replace('cypress/integration/', 'cypress/integration/').replace('.coffee', '.js')12}13const transform = async (filePath) => {14 const code = await readFile(filePath, 'utf8')15 const result = await babel.transformAsync(code, {
Using AI Code Generation
1const babel = require('babel-core')2const fs = require('fs')3const path = require('path')4const { promisify } = require('util')5const readFile = promisify(fs.readFile)6const writeFile = promisify(fs.writeFile)7const getJsPath = (filePath) => {8 return filePath.replace('.coffee', '.js')9}10const getJsPathFromTest = (filePath) => {11 return filePath.replace('cypress/integration/', 'cypress/integration/').replace('.coffee', '.js')12}13const transform = async (filePath) => {14 const code = await readFile(filePath, 'utf8')15 const result = await babel.transformAsync(code, {
Using AI Code Generation
1const babel = require('@babel/core');2const babelOptions = {3 {4 targets: {5 },6 },7};8const babelTransform = (code, options = {}) => {9 return babel.transformAsync(code, {10 });11};12module.exports = (on, config) => {13 on('file:preprocessor', file => {14 return babelTransform(file.filePath, {15 });16 });17};18const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin');
Using AI Code Generation
1CyprosveCommands.add('compile', (code) => {2 return cy.task('compile', code)3})4module.exports = (on, config) => {5 on('task', {6 compile (code) {7 return babel.transformAsync(code, {8 })9 },10 })11}12describe('Test', () => {13 it('should compile', () => {14 cy.get('button').click()15 cy.compile('const a = 1').then((result) => {16 expect(result.code).to.include('const a = 1')17 })18 })19})rage/task');20module.exports = (on, config) => {21 addMatchImageSnapshotPlugin(on, config);22 installCoverage(on, config);23 return config;24};25import '@cypress/code-coverage/support';26describe('my app', () => {27 it('works', () => {28 cy.visit('/');29 cy.contains('h1', 'Hello World');30 });31});32{33 "nyc": {34 }35}36### How to get coverage for files that are not imported by tests?
Using AI Code Generation
1Cypress.Commands.add('compile', (code) => {2 return cy.task('compile', code)3})4module.exports = (on, config) => {5 on('task', {6 compile (code) {7 return babel.transformAsync(code, {8 })9 },10 })11}12describe('Test', () => {13 it('should compile', () => {14 cy.get('button').click()15 cy.compile('const a = 1').then((result) => {16 expect(result.code).to.include('const a = 1')17 })18 })19})
Using AI Code Generation
1const babel = require('@babel/core')2const fs = require('fs')3const path = require('path')4const cypress = require('cypress')5const babelConfig = {6 {7 targets: {8 },9 },10}11const babelOptions = {12}13async function runTests() {14 const { code } = await babel.transformFileAsync(15 path.join(__dirname, 'src', 'index.js'),16 fs.writeFileSync(path.join(__dirname, 'dist', 'index.js'), code)17 await cypress.run()18}19runTests()
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.get('.test')4 .should('have.text', 'Test')5 .click()6 .should('have.text', 'Test clicked')7 })8})9module.exports = (on, config) => {10 on('file:preprocessor', require('@cypress/code-coverage/use-babelrc'))11}12module.exports = (on, config) => {13 on('file:preprocessor', require('@cypress/code-coverage/use-babelrc')({14 babelConfig: {15 }16 }))17}18module.exports = (on, config) => {19 on('file:preprocessor', require('@cypress/code-coverage/use-babelrc')({20 }))21}
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!