Skip to content

Commit

Permalink
Add cjs test + github actions
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Nov 27, 2023
1 parent c877101 commit 937d7d2
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
ignore:
- dependency-name: standard
versions:
- 16.0.3
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: ci

on:
push:
paths-ignore:
- 'docs/**'
- '*.md'
pull_request:
paths-ignore:
- 'docs/**'
- '*.md'

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x, 21.x]
steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install
run: |
npm install
- name: Run tests
run: |
npm run test
3 changes: 2 additions & 1 deletion borp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import runWithTypeScript from './lib/run.js'

let reporter
if (process.stdout.isTTY) {
reporter = spec()
/* eslint new-cap: "off" */
reporter = new spec()
} else {
reporter = tap
}
Expand Down
3 changes: 3 additions & 0 deletions fixtures/ts-cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
4 changes: 4 additions & 0 deletions fixtures/ts-cjs/src/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export function add (x: number, y: number): number {
return x + y
}
7 changes: 7 additions & 0 deletions fixtures/ts-cjs/test/add.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'node:test'
import { add } from '../src/add.js'
import { strictEqual } from 'node:assert'

test('add', () => {
strictEqual(add(1, 2), 3)
})
7 changes: 7 additions & 0 deletions fixtures/ts-cjs/test/add2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'node:test'
import { add } from '../src/add.js'
import { strictEqual } from 'node:assert'

test('add2', () => {
strictEqual(add(3, 2), 5)
})
23 changes: 23 additions & 0 deletions fixtures/ts-cjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"outDir": "dist",
"sourceMap": true,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"strict": true,
"resolveJsonModule": true,
"removeComments": true,
"newLine": "lf",
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"lib": [
"ESNext"
]
}
}
19 changes: 19 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,22 @@ test('ts-esm', async (t) => {

await completed
})

test('ts-cjs', async (t) => {
const { strictEqual, completed } = tspl(t, { plan: 2 })
const config = {
files: [],
cwd: join(import.meta.url, '..', 'fixtures', 'ts-cjs')
}

const stream = await runWithTypeScript(config)

const names = new Set(['add', 'add2'])

stream.on('test:pass', (test) => {
strictEqual(names.has(test.name), true)
names.delete(test.name)
})

await completed
})

0 comments on commit 937d7d2

Please sign in to comment.