Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing basics with jest #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"dev": "tsc --watch",
"build": "tsc",
"prepublish": "npm run build"
"prepublish": "npm run build",
"test": "jest"
},
"repository": {
"type": "git",
Expand All @@ -26,7 +27,11 @@
},
"homepage": "https://github.com/pd4d10/vite-plugin-svgr#readme",
"devDependencies": {
"@babel/preset-env": "^7.15.0",
"@babel/preset-typescript": "^7.15.0",
"@types/node": "^15.12.2",
"jest": "^27.0.6",
"ts-node": "^10.2.0",
"typescript": "^4.3.2",
"vite": "^2.3.7"
},
Expand Down
24 changes: 24 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {join} from 'path';
import svgr from '.';
describe('svgr plugin', () => {
it('should work with no configs', async () => {
expect(
await svgr().transform(
'// some code here',
join(__dirname, 'test.svg'))).
toMatchInlineSnapshot(`
Object {
"code": "import * as React from \\"react\\";
function ReactComponent(props) {
return /* @__PURE__ */ React.createElement(\\"svg\\", {
xmlns: \\"http://www.w3.org/2000/svg\\",
...props
}, /* @__PURE__ */ React.createElement(\\"text\\", null, \\"SVG\\"));
}
export { ReactComponent };
",
"map": null,
}
`)
})
})
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import type { Plugin } from 'vite'
import type {Plugin} from 'vite'
import type * as E from 'esbuild'

export = function svgrPlugin(): Plugin {
export default function svgrPlugin(): Plugin {
// TODO: options
return {
name: 'vite:svgr',
Expand All @@ -16,7 +16,7 @@ export = function svgrPlugin(): Plugin {
const componentCode = await svgr(
svg,
{},
{ componentName: 'ReactComponent' }
{componentName: 'ReactComponent'}
).then((res: string) => {
return res.replace(
'export default ReactComponent',
Expand Down