Skip to content

Commit 9f8168d

Browse files
committed
added tests
1 parent 8403085 commit 9f8168d

File tree

6 files changed

+1718
-15
lines changed

6 files changed

+1718
-15
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/node_modules
2+
/.nyc_output
3+
/coverage

.gitlab-ci.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
image: node:lts-alpine
2+
3+
cache:
4+
paths:
5+
- node_modules/
6+
7+
stages:
8+
- test
9+
- audit
10+
11+
test:
12+
stage: test
13+
except:
14+
- schedules
15+
script:
16+
- yarn install
17+
- yarn test:ci
18+
coverage: '/^Statements\s*:\s*([^%]+)/'
19+
20+
audit:
21+
stage: audit
22+
only:
23+
- schedules
24+
script:
25+
- yarn audit

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ npm install @uscreen.de/common-esm
1717
## Usage
1818

1919
```js
20-
import { dirname, filename, join, json, isMain } from '@uscreen.de/common-esm'
20+
import { dirname, filename, join, requireJson, isMain } from '@uscreen.de/common-esm'
2121

2222
// --- provided by desm ---
2323

index.test.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import tap from 'tap'
2+
import { fileURLToPath } from 'url'
3+
import { dirname as dirnamePath } from 'path'
4+
import { dirname, filename, join, requireJson, isMain } from './index.js'
5+
6+
tap.test('Test Setup', (t) => {
7+
t.equal(true, true, 'Tests and assertions should work')
8+
t.end()
9+
})
10+
11+
const __dirname = dirnamePath(fileURLToPath(import.meta.url))
12+
const __filename = fileURLToPath(import.meta.url)
13+
14+
tap.test('dirname', (t) => {
15+
t.equal(
16+
dirname(import.meta.url),
17+
__dirname,
18+
'dirname should return the current directory'
19+
)
20+
t.end()
21+
})
22+
23+
tap.test('filename', (t) => {
24+
t.equal(
25+
filename(import.meta.url),
26+
__filename,
27+
'filename should return the current file'
28+
)
29+
t.end()
30+
})
31+
32+
tap.test('join', (t) => {
33+
t.equal(
34+
join(import.meta.url, 'a', 'b', 'c'),
35+
`${__dirname}/a/b/c`,
36+
'join should join the given paths'
37+
)
38+
t.end()
39+
})
40+
41+
tap.test('requireJson', (t) => {
42+
t.equal(
43+
requireJson(import.meta.url, './package.json').name,
44+
'@uscreen.de/common-esm',
45+
'requireJson should require a JSON file'
46+
)
47+
t.end()
48+
})
49+
50+
tap.test('isMain', (t) => {
51+
t.equal(isMain(import.meta.url), true, 'isMain should return true')
52+
t.end()
53+
})

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
"repository": "[email protected]:uscreen/npm/common-esm.git",
88
"author": "Marcus Spiegel <[email protected]>",
99
"license": "MIT",
10+
"scripts": {
11+
"test": "c8 tap",
12+
"test:cov": "c8 --reporter=html --reporter=text tap",
13+
"test:ci": "c8 --reporter=text-summary tap"
14+
},
1015
"dependencies": {
1116
"desm": "^1.3.0"
1217
},
1318
"devDependencies": {
14-
"@uscreen.de/eslint-config-prettystandard-node": "^0.2.10"
19+
"@uscreen.de/eslint-config-prettystandard-node": "^0.2.10",
20+
"c8": "^7.12.0",
21+
"tap": "^16.3.0"
1522
}
1623
}

0 commit comments

Comments
 (0)