Skip to content

Commit

Permalink
test: replace jest-file-snapshot with jest-image-snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKruckenberg committed Apr 9, 2021
1 parent f612e6a commit f9b3b16
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 113 deletions.
3 changes: 2 additions & 1 deletion packages/rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
"@babel/preset-env": "^7.13.12",
"@babel/preset-typescript": "^7.13.0",
"@types/jest": "^26.0.22",
"@types/jest-image-snapshot": "^4.3.0",
"babel-jest": "^26.6.3",
"jest": "^26.6.3",
"jest-file-snapshot": "^0.5.0",
"jest-image-snapshot": "^4.4.1",
"rollup": "^2.44.0",
"rollup-plugin-typescript2": "^0.30.0",
"typescript": "^4.2.3"
Expand Down

This file was deleted.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 49 additions & 48 deletions packages/rollup/src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { rollup } from 'rollup'
import { imagetools } from '../index'
import { join } from 'path'
import { testEntry, getSource } from './util'
import { toMatchFile } from 'jest-file-snapshot'
import { toMatchImageSnapshot } from 'jest-image-snapshot'

expect.extend({ toMatchFile })
expect.extend({ toMatchImageSnapshot })
process.chdir(join(__dirname, 'fixtures'))

describe('rollup-plugin-imagetools', () => {
Expand All @@ -13,136 +13,136 @@ describe('rollup-plugin-imagetools', () => {
it('accepts a string', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg?w=300"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png?w=300"`),
imagetools({
include: '**/*.jpg?*'
include: '**/*.png?*'
})
]
})

expect(p).resolves.toBeDefined()
await expect(p).resolves.toBeDefined()
})

it('accepts a regex', () => {
it('accepts a regex', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg?w=300"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png?w=300"`),
imagetools({
include: /\w+\.jpg/
include: /\w+\.png/
})
]
})

expect(p).resolves.toBeDefined()
await expect(p).resolves.toBeDefined()
})

it('accepts an array', () => {
it('accepts an array', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg?w=300"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png?w=300"`),
imagetools({
include: ['**/*.jpg?*', /\w+\.jpg/]
include: ['**/*.png?*', /\w+\.png/]
})
]
})

expect(p).resolves.toBeDefined()
await expect(p).resolves.toBeDefined()
})

it('errors on invalid input', () => {
it('errors on invalid input', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg?w=300"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png?w=300"`),
imagetools({
//@ts-ignore
include: 100
})
]
})

expect(p).rejects.toBeDefined()
await expect(p).rejects.toBeDefined()
})

it('rejects on non matching import', async () => {
// because rollup cant resolve images by itself
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg?w=300"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png?w=300"`),
imagetools({
include: ''
})
]
})

expect(p).rejects.toBeDefined()
await expect(p).rejects.toBeDefined()
})
})

describe('exclude', () => {
it('accepts a string', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg?w=300"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png?w=300"`),
imagetools({
exclude: '**/*.png'
exclude: '**/*.jpg'
})
]
})

expect(p).resolves.toBeDefined()
await expect(p).resolves.toBeDefined()
})

it('accepts a regex', () => {
it('accepts a regex', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg?w=300"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png?w=300"`),
imagetools({
exclude: /\w+\.png/
exclude: /\w+\.jpg/
})
]
})

expect(p).resolves.toBeDefined()
await expect(p).resolves.toBeDefined()
})

it('accepts an array', () => {
it('accepts an array', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg?w=300"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png?w=300"`),
imagetools({
exclude: ['**/*.png?*', /\w+\.png/]
exclude: ['**/*.jpg?*', /\w+\.jpg/]
})
]
})

expect(p).resolves.toBeDefined()
await expect(p).resolves.toBeDefined()
})

it('errors on invalid input', () => {
it('errors on invalid input', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg?w=300"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png?w=300"`),
imagetools({
//@ts-ignore
exclude: 100
})
]
})

expect(p).rejects.toBeDefined()
await expect(p).rejects.toBeDefined()
})

it('resolves normal on non matching input', () => {
it('resolves normal on non matching input', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg?w=300"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png?w=300"`),
imagetools({
exclude: ''
})
]
})

expect(p).resolves.toBeDefined()
await expect(p).resolves.toBeDefined()
})
})

Expand All @@ -158,22 +158,23 @@ describe('rollup-plugin-imagetools', () => {
})
})

test('relative import', async () => {
test('relative path', async () => {
const bundle = await rollup({
plugins: [
testEntry(`
import Image from "./pexels-allec-gomes-5195763.jpg?w=300"
import Image from "./pexels-allec-gomes-5195763.png?w=300"
export default Image
`),
imagetools()
]
})

const source = await getSource(bundle)
expect(source).toMatchFile()
const source = await getSource(bundle)
expect(source).toMatchImageSnapshot()
})
test('absolute import', async () => {
const imagePath = join(process.cwd(), 'pexels-allec-gomes-5195763.jpg')

test('absolute path', async () => {
const imagePath = join(process.cwd(), 'pexels-allec-gomes-5195763.png')

const bundle = await rollup({
plugins: [
Expand All @@ -186,28 +187,28 @@ describe('rollup-plugin-imagetools', () => {
})

const source = await getSource(bundle)
expect(source).toMatchFile()
expect(source).toMatchImageSnapshot()
})

test('non existent file', () => {
test('non existent file', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./invalid.jpg?w=300"`),
testEntry(`import Image from "./invalid.png?w=300"`),
imagetools()
]
})

expect(p).rejects.toBeDefined()
await expect(p).rejects.toBeDefined()
})

test('no directives', () => {
test('no directives', async () => {
const p = rollup({
plugins: [
testEntry(`import Image from "./pexels-allec-gomes-5195763.jpg"`),
testEntry(`import Image from "./pexels-allec-gomes-5195763.png"`),
imagetools()
]
})

expect(p).rejects.toBeDefined()
await expect(p).rejects.toBeDefined()
})
})
1 change: 1 addition & 0 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@types/jest": "^26.0.20",
"babel-jest": "^26.6.3",
"jest": "^26.6.3",
"jest-image-snapshot": "^4.4.1",
"rollup": "^2.41.2",
"rollup-plugin-typescript2": "^0.30.0",
"ts-jest": "^26.5.3",
Expand Down
1 change: 0 additions & 1 deletion packages/vite/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default {
dir: 'dist',
format: 'cjs',
sourcemap: true,
exports: 'default',
entryFileNames: '[name].cjs',
chunkFileNames: '[name].cjs'
},
Expand Down

This file was deleted.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f9b3b16

Please sign in to comment.