-
Notifications
You must be signed in to change notification settings - Fork 6
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 #10 from ksoichiro/fix-config-for-ts-and-cjs
Keep previous usage, fix package config, and add tests to confirm examples work
- Loading branch information
Showing
20 changed files
with
239 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
beforeAll(() => { | ||
process.chdir('examples/cjs') | ||
}) | ||
|
||
afterAll(() => { | ||
process.chdir('../..') | ||
}) | ||
|
||
test('example works', () => { | ||
console.log = jest.fn() | ||
require('./example.js') | ||
expect(console.log).toHaveBeenCalledWith(`<p><img src="img.png" alt="" width="640" height="480"></p>`) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -7,5 +7,8 @@ | |
"remark-rehype": "^8.1.0", | ||
"to-vfile": "^6.1.0", | ||
"unified": "^9.2.2" | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
} | ||
} |
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,15 @@ | ||
import {jest} from '@jest/globals' | ||
|
||
beforeAll(() => { | ||
process.chdir('examples/cjs') | ||
}) | ||
|
||
afterAll(() => { | ||
process.chdir('../..') | ||
}) | ||
|
||
test('example works', async () => { | ||
console.log = jest.fn() | ||
await import('./example.js') | ||
expect(console.log).toHaveBeenCalledWith(`<p><img src="img.png" alt="" width="640" height="480"></p>`) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 @@ | ||
/node_modules/ | ||
/example.js |
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,15 @@ | ||
import {jest} from '@jest/globals' | ||
|
||
beforeAll(() => { | ||
process.chdir('examples/cjs') | ||
}) | ||
|
||
afterAll(() => { | ||
process.chdir('../..') | ||
}) | ||
|
||
test('example works', async () => { | ||
console.log = jest.fn() | ||
await import('./example.js') | ||
expect(console.log).toHaveBeenCalledWith(`<p><img src="img.png" alt="" width="640" height="480"></p>`) | ||
}) |
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,17 @@ | ||
import {unified} from 'unified' | ||
import parse from 'remark-parse' | ||
import remark2rehype from 'remark-rehype' | ||
import stringify from 'rehype-stringify' | ||
import * as vfile from 'to-vfile' | ||
import rehypeImgSize from 'rehype-img-size' | ||
|
||
unified() | ||
.use(parse) | ||
.use(remark2rehype) | ||
.use(rehypeImgSize) | ||
.use(stringify) | ||
.process(vfile.readSync('index.md'), function(err, file) { | ||
if (err) throw err | ||
if (!file) return | ||
console.log(file.value) | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
![](img.png) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 @@ | ||
{ | ||
"private": true, | ||
"type": "module", | ||
"devDependencies": { | ||
"@types/node": "^17.0.10", | ||
"rehype-img-size": "file:../..", | ||
"typescript": "^4.5.5" | ||
}, | ||
"scripts": { | ||
"build": "tsc -p .", | ||
"test": "NODE_OPTIONS=--experimental-vm-modules jest" | ||
} | ||
} |
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,9 @@ | ||
## Example of usage as TypeScript | ||
|
||
To try example, run following: | ||
|
||
``` | ||
npm install | ||
npm run build | ||
node example.js | ||
``` |
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,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "es2015", | ||
"skipLibCheck": true, | ||
"moduleResolution": "node" | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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