Skip to content

Commit 50e8791

Browse files
committed
feat: add installation verification tests for CommonJS and ESM
- Introduced a new script to run installation verification tests for both CommonJS and ESM modules. - Created test directories with corresponding package.json files for CommonJS and ESM installations. - Each test logs the results of the installation verification process, ensuring that the README install instructions are accurate.
1 parent 978a6ec commit 50e8791

5 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const analytics = require('analytics')
2+
3+
console.log(analytics)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "cjs-install-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "node index.js"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"analytics": "file:../../../../packages/analytics"
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Analytics from 'analytics'
2+
3+
console.log('Analytics:', Analytics)
4+
console.log('Analytics type:', typeof Analytics)
5+
console.log('Analytics keys:', Object.keys(Analytics))
6+
7+
// Try the workaround
8+
try {
9+
const analytics = Analytics.default({
10+
app: 'awesome-app',
11+
plugins: []
12+
})
13+
console.log('Success with Analytics.default!')
14+
} catch (error) {
15+
console.error('Failed with Analytics.default:', error.message)
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "esm-install-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"test": "node index.js"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"analytics": "file:../../../../packages/analytics"
15+
}
16+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env node
2+
3+
const { execSync } = require('child_process')
4+
const path = require('path')
5+
6+
console.log('🧪 Running installation verification tests...\n')
7+
8+
// Test CommonJS installation
9+
console.log('📦 Testing CommonJS installation...')
10+
try {
11+
const cjsOutput = execSync('npm test', {
12+
cwd: path.join(__dirname, 'cjs-test'),
13+
encoding: 'utf8'
14+
})
15+
console.log('✅ CommonJS test passed')
16+
// console.log(cjsOutput)
17+
} catch (error) {
18+
console.log('❌ CommonJS test failed')
19+
console.log(error.stdout || error.message)
20+
process.exit(1)
21+
}
22+
23+
// Test ESM installation
24+
console.log('\n📦 Testing ESM installation...')
25+
try {
26+
const esmOutput = execSync('npm test', {
27+
cwd: path.join(__dirname, 'esm-test'),
28+
encoding: 'utf8'
29+
})
30+
console.log('✅ ESM test passed')
31+
// console.log(esmOutput)
32+
} catch (error) {
33+
console.log('❌ ESM test failed')
34+
console.log(error.stdout || error.message)
35+
process.exit(1)
36+
}
37+
38+
console.log('\n🎉 All installation tests passed!')
39+
console.log('📝 README install instructions are verified as correct.')

0 commit comments

Comments
 (0)