-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from ljharb/add_react
Add react import
- Loading branch information
Showing
4 changed files
with
57 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import MySvg from './close.svg'; | ||
|
||
export function MyFunctionIcon() { | ||
return MySvg; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,51 @@ | ||
import { transformFile } from 'babel-core'; | ||
|
||
function assertReactImport(result) { | ||
const match = result.code.match(/import React from 'react'/); | ||
if (!match) { | ||
throw new Error('no React import found'); | ||
} | ||
if (match.length !== 1) { | ||
throw new Error('more or less than one match found'); | ||
} | ||
} | ||
|
||
transformFile('test/fixtures/test.jsx', { | ||
presets: ['airbnb'], | ||
babelrc: false, | ||
presets: ['react'], | ||
plugins: [ | ||
'../../src/index', | ||
], | ||
}, (err, result) => { | ||
if (err) throw err; | ||
console.log(result.code); | ||
assertReactImport(result); | ||
console.log('test/fixtures/test.jsx', result.code); | ||
}); | ||
|
||
transformFile('test/fixtures/test-case-sensitive.jsx', { | ||
presets: ['airbnb'], | ||
transformFile('test/fixtures/test-no-react.jsx', { | ||
babelrc: false, | ||
presets: ['react'], | ||
plugins: [ | ||
['../../src/index', | ||
{ | ||
"caseSensitive": true | ||
}] | ||
'../../src/index', | ||
], | ||
}, (err, result) => { | ||
if (err) throw err; | ||
console.log('test/fixtures/test-no-react.jsx', result.code); | ||
assertReactImport(result); | ||
}); | ||
|
||
transformFile('test/fixtures/test-case-sensitive.jsx', { | ||
babelrc: false, | ||
presets: ['react'], | ||
plugins: [ | ||
['../../src/index', { | ||
caseSensitive: true, | ||
}], | ||
], | ||
}, (err) => { | ||
if (err && err.message.indexOf('match case') !== -1) { | ||
console.log("Test passed: Expected case sensitive error was thrown"); | ||
console.log('test/fixtures/test-case-sensitive.jsx', 'Test passed: Expected case sensitive error was thrown'); | ||
} else { | ||
throw new Error("Test failed: Expected case sensitive error wasn't thrown"); | ||
} | ||
}); | ||
}); |