Skip to content

Commit

Permalink
Ignore template spec at creation step
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Sep 15, 2024
1 parent fe5702f commit 37e40ae
Show file tree
Hide file tree
Showing 61 changed files with 1,069 additions and 35 deletions.
1 change: 0 additions & 1 deletion examples/action-chatgpt/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
1 change: 0 additions & 1 deletion examples/action/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
1 change: 0 additions & 1 deletion examples/config-babel/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
1 change: 0 additions & 1 deletion examples/config-stylelint/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
1 change: 0 additions & 1 deletion examples/content-css-module/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
39 changes: 39 additions & 0 deletions examples/content-css-module/template.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path from 'path'
import {execSync} from 'child_process'
import {extensionFixtures} from '../extension-fixtures'

const exampleDir = 'examples/content-css-module'
const pathToExtension = path.join(__dirname, `dist/chrome`)
const test = extensionFixtures(pathToExtension, true)

test.beforeAll(async () => {
execSync(`pnpm extension build ${exampleDir}`, {
cwd: path.join(__dirname, '..')
})
})

test('should exist an element with the class name content_script-box', async ({
page
}) => {
await page.goto('https://extension.js.org/')
const div = page.locator('body > div.content_script-box')
await test.expect(div).toBeVisible()
})

test('should exist an h1 element with specified content', async ({page}) => {
await page.goto('https://extension.js.org/')
const h1 = page.locator('body > div.content_script-box > h1')
await test.expect(h1).toHaveText('Change the background-color ⬇')
})

test('should exist a default color value', async ({page}) => {
await page.goto('https://extension.js.org/')
const h1 = page.locator('body > div.content_script-box > h1')
const color = await page.evaluate(
(locator) => {
return window.getComputedStyle(locator!).getPropertyValue('color')
},
await h1.elementHandle()
)
await test.expect(color).toEqual('rgb(51, 51, 51)')
})
1 change: 0 additions & 1 deletion examples/content-extension-config/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
72 changes: 72 additions & 0 deletions examples/content-extension-config/template.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import path from 'path'
import {execSync} from 'child_process'
import {extensionFixtures} from '../extension-fixtures'

const exampleDir = 'examples/content-extension-config'
const pathToExtension = path.join(__dirname, `dist/chrome`)
const test = extensionFixtures(pathToExtension, true)

test.beforeAll(async () => {
execSync(`pnpm extension build ${exampleDir}`, {
cwd: path.join(__dirname, '..')
})
})

test('should exist an element with the class name extension-root', async ({
page
}) => {
await page.goto('https://extension.js.org/')
const div = page.locator('#extension-root')
await test.expect(div).toBeVisible()
})

test('should exist an h2 element with specified content', async ({page}) => {
await page.goto('https://extension.js.org/')
const h2 = page.locator('#extension-root h2')
await test
.expect(h2)
.toHaveText(
'This is a content script running React, TypeScript, and Tailwind.css'
)
})

test('should exist a default color value', async ({page}) => {
await page.goto('https://extension.js.org/')
const h2 = page.locator('#extension-root h2')
const color = await page.evaluate(
(locator) => {
return window.getComputedStyle(locator!).getPropertyValue('color')
},
await h2.elementHandle()
)
await test.expect(color).toEqual('rgb(255, 255, 255)')
})

test('should load all images successfully', async ({page}) => {
await page.goto('https://extension.js.org/')
const images = page.locator('#extension-root img')
const imageElements = await images.all()

const results: boolean[] = []

for (const image of imageElements) {
const naturalWidth = await page.evaluate(
(img) => {
return img ? (img as HTMLImageElement).naturalWidth : 0
},
await image.elementHandle()
)

const naturalHeight = await page.evaluate(
(img) => {
return img ? (img as HTMLImageElement).naturalHeight : 0
},
await image.elementHandle()
)

const loadedSuccessfully = naturalWidth > 0 && naturalHeight > 0
results.push(loadedSuccessfully)
}

await test.expect(results.every((result) => result)).toBeTruthy()
})
1 change: 0 additions & 1 deletion examples/content-less/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
39 changes: 39 additions & 0 deletions examples/content-less/template.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path from 'path'
import {execSync} from 'child_process'
import {extensionFixtures} from '../extension-fixtures'

const exampleDir = 'examples/content-less'
const pathToExtension = path.join(__dirname, `dist/chrome`)
const test = extensionFixtures(pathToExtension, true)

test.beforeAll(async () => {
execSync(`pnpm extension build ${exampleDir}`, {
cwd: path.join(__dirname, '..')
})
})

test('should exist an element with the class name content_script-box', async ({
page
}) => {
await page.goto('https://extension.js.org/')
const div = page.locator('body > div.content_script-box')
await test.expect(div).toBeVisible()
})

test('should exist an h1 element with specified content', async ({page}) => {
await page.goto('https://extension.js.org/')
const h1 = page.locator('body > div.content_script-box > h1')
await test.expect(h1).toHaveText('Change the background-color ⬇')
})

test('should exist a default color value', async ({page}) => {
await page.goto('https://extension.js.org/')
const h1 = page.locator('body > div.content_script-box > h1')
const color = await page.evaluate(
(locator) => {
return window.getComputedStyle(locator!).getPropertyValue('color')
},
await h1.elementHandle()
)
await test.expect(color).toEqual('rgb(51, 51, 51)')
})
1 change: 0 additions & 1 deletion examples/content-main-world/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
39 changes: 39 additions & 0 deletions examples/content-main-world/template.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path from 'path'
import {execSync} from 'child_process'
import {extensionFixtures} from '../extension-fixtures'

const exampleDir = 'examples/content-main-world'
const pathToExtension = path.join(__dirname, `dist/chrome`)
const test = extensionFixtures(pathToExtension, true)

test.beforeAll(async () => {
execSync(`pnpm extension build ${exampleDir}`, {
cwd: path.join(__dirname, '..')
})
})

test('should exist an element with the class name content_script-box', async ({
page
}) => {
await page.goto('https://extension.js.org/')
const div = page.locator('body > div.content_script-box')
await test.expect(div).toBeVisible()
})

test('should exist an h1 element with specified content', async ({page}) => {
await page.goto('https://extension.js.org/')
const h1 = page.locator('body > div.content_script-box > h1')
await test.expect(h1).toHaveText('Main World')
})

test('should exist a default color value', async ({page}) => {
await page.goto('https://extension.js.org/')
const h1 = page.locator('body > div.content_script-box > h1')
const color = await page.evaluate(
(locator) => {
return window.getComputedStyle(locator!).getPropertyValue('color')
},
await h1.elementHandle()
)
await test.expect(color).toEqual('rgb(51, 51, 51)')
})
1 change: 0 additions & 1 deletion examples/content-preact/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
72 changes: 72 additions & 0 deletions examples/content-preact/template.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import path from 'path'
import {execSync} from 'child_process'
import {extensionFixtures} from '../extension-fixtures'

const exampleDir = 'examples/content-preact'
const pathToExtension = path.join(__dirname, `dist/chrome`)
const test = extensionFixtures(pathToExtension, true)

test.beforeAll(async () => {
execSync(`pnpm extension build ${exampleDir}`, {
cwd: path.join(__dirname, '..')
})
})

test('should exist an element with the class name extension-root', async ({
page
}) => {
await page.goto('https://extension.js.org/')
const div = page.locator('#extension-root')
await test.expect(div).toBeVisible()
})

test('should exist an h2 element with specified content', async ({page}) => {
await page.goto('https://extension.js.org/')
const h2 = page.locator('#extension-root h2')
await test
.expect(h2)
.toHaveText(
'This is a content script running Preact, TypeScript, and Tailwind.css.'
)
})

test('should exist a default color value', async ({page}) => {
await page.goto('https://extension.js.org/')
const h2 = page.locator('#extension-root h2')
const color = await page.evaluate(
(locator) => {
return window.getComputedStyle(locator!).getPropertyValue('color')
},
await h2.elementHandle()
)
await test.expect(color).toEqual('rgb(255, 255, 255)')
})

test('should load all images successfully', async ({page}) => {
await page.goto('https://extension.js.org/')
const images = page.locator('#extension-root img')
const imageElements = await images.all()

const results: boolean[] = []

for (const image of imageElements) {
const naturalWidth = await page.evaluate(
(img) => {
return img ? (img as HTMLImageElement).naturalWidth : 0
},
await image.elementHandle()
)

const naturalHeight = await page.evaluate(
(img) => {
return img ? (img as HTMLImageElement).naturalHeight : 0
},
await image.elementHandle()
)

const loadedSuccessfully = naturalWidth > 0 && naturalHeight > 0
results.push(loadedSuccessfully)
}

await test.expect(results.every((result) => result)).toBeTruthy()
})
1 change: 0 additions & 1 deletion examples/content-react-svgr/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
1 change: 0 additions & 1 deletion examples/content-react/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
72 changes: 72 additions & 0 deletions examples/content-react/template.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import path from 'path'
import {execSync} from 'child_process'
import {extensionFixtures} from '../extension-fixtures'

const exampleDir = 'examples/content-react'
const pathToExtension = path.join(__dirname, `dist/chrome`)
const test = extensionFixtures(pathToExtension, true)

test.beforeAll(async () => {
execSync(`pnpm extension build ${exampleDir}`, {
cwd: path.join(__dirname, '..')
})
})

test('should exist an element with the class name extension-root', async ({
page
}) => {
await page.goto('https://extension.js.org/')
const div = page.locator('#extension-root')
await test.expect(div).toBeVisible()
})

test('should exist an h2 element with specified content', async ({page}) => {
await page.goto('https://extension.js.org/')
const h2 = page.locator('#extension-root h2')
await test
.expect(h2)
.toHaveText(
'This is a content script running React, TypeScript, and Tailwind.css'
)
})

test('should exist a default color value', async ({page}) => {
await page.goto('https://extension.js.org/')
const h2 = page.locator('#extension-root h2')
const color = await page.evaluate(
(locator) => {
return window.getComputedStyle(locator!).getPropertyValue('color')
},
await h2.elementHandle()
)
await test.expect(color).toEqual('rgb(255, 255, 255)')
})

test('should load all images successfully', async ({page}) => {
await page.goto('https://extension.js.org/')
const images = page.locator('#extension-root img')
const imageElements = await images.all()

const results: boolean[] = []

for (const image of imageElements) {
const naturalWidth = await page.evaluate(
(img) => {
return img ? (img as HTMLImageElement).naturalWidth : 0
},
await image.elementHandle()
)

const naturalHeight = await page.evaluate(
(img) => {
return img ? (img as HTMLImageElement).naturalHeight : 0
},
await image.elementHandle()
)

const loadedSuccessfully = naturalWidth > 0 && naturalHeight > 0
results.push(loadedSuccessfully)
}

await test.expect(results.every((result) => result)).toBeTruthy()
})
1 change: 0 additions & 1 deletion examples/content-sass-module/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ yarn-error.log*

# extension.js
extension-env.d.ts
template.spec.ts
Loading

0 comments on commit 37e40ae

Please sign in to comment.