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

feat: add initial test setup #58

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add initial test setup
  • Loading branch information
craftamap committed Aug 28, 2024
commit acd2a511587905f300319c6c2759d388fdaa3787
25 changes: 21 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '21'
- name: install dependencies
run: yarn
run: yarn install
- name: Run build
run: yarn build
- name: Detect unwanted changes
Expand All @@ -15,8 +18,22 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '21'
- name: install dependencies
run: yarn
run: yarn install
- name: Run lint
run: yarn lint
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '21'
- name: install dependencies
run: yarn install
- name: Run test
run: yarn test
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"scripts": {
"build": "tsc",
"lint": "eslint src/**"
"lint": "eslint src/**",
"test": "node --test \"**/*.test.mjs\""
},
"author": "Fabian Siegel <[email protected]>",
"license": "MIT",
Expand All @@ -25,7 +26,7 @@
"@types/node": "^16.9.1",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"esbuild": "^0.15.10",
"esbuild": "^0.21.1",
"eslint": "^8.8.0",
"typescript": "^4.5.5"
},
Expand Down
51 changes: 51 additions & 0 deletions test/e2e/index.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { describe, it, beforeEach, afterEach } from 'node:test'
import { htmlPlugin } from '../../lib/cjs/index.js'
import * as fsPromises from 'fs/promises'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import * as assert from 'assert'

describe('esbuild-plugin-html', () => {
let savedDir
beforeEach(async () => {
savedDir = process.cwd()
const testDir = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'esbuild-plugin-html_'))
console.log(testDir)
process.chdir(testDir)
})
afterEach(() => {
process.chdir(savedDir)
})
it('creates a html file for a simple entry file', async () => {
await fsPromises.mkdir('src/')
await fsPromises.writeFile('src/index.ts', '')

// esbuild should default to the current cwd, but during import. using dynamic imports, we can avoid this.
const esbuild = await import('esbuild')
await esbuild.build({
entryPoints: ['src/index.ts'],
metafile: true,
outdir: './out',
logLevel: 'info',
plugins: [htmlPlugin({
files: [
{
filename: 'index.html',
entryPoints: ['src/index.ts'],
},
]
})]
})

assert.ok(fs.existsSync('out/index.html'))
assert.strictEqual(await fsPromises.readFile('out/index.html', 'utf8'), `<!DOCTYPE html><html><head>
<meta charset="utf-8">
</head>
<body>


<script src="index.js" defer=""></script></body></html>`
)
})
})
Loading