1- // Smoke test script to verify compiled dist builds work correctly with Node.js
1+ // Smoke test script to verify compiled CJS dist build works correctly with Node.js
22// This ensures the actual published artifacts function properly
33
44import { execSync } from 'child_process'
@@ -51,15 +51,9 @@ async function runDistSmokeTests() {
5151 // Create package.json and install dependencies for proper Node.js environment
5252 await setupTestEnvironment ( )
5353
54- // Test ESM dist import
55- await testESMDist ( )
56-
5754 // Test CJS dist require
5855 await testCJSDist ( )
5956
60- // Test ESM tree-sitter functionality
61- await testESMTreeSitter ( )
62-
6357 // Test CJS tree-sitter functionality
6458 await testCJSTreeSitter ( )
6559
@@ -91,7 +85,7 @@ async function setupTestEnvironment() {
9185 const testPackageJson = {
9286 name : 'sdk-dist-test' ,
9387 version : '1.0.0' ,
94- type : 'module ' ,
88+ type : 'commonjs ' ,
9589 dependencies : {
9690 'web-tree-sitter' : '^0.25.6' ,
9791 // Add other dependencies that the built dist files need
@@ -113,65 +107,14 @@ async function setupTestEnvironment() {
113107 }
114108}
115109
116- async function testESMDist ( ) {
117- console . log ( ' Testing ESM dist import with Node.js...' )
118-
119- const testFile = join ( testDir , 'test-esm-dist.mjs' )
120- const testCode = `
121- try {
122- // Import from the built ESM dist files
123- const pkg = await import('../dist/esm/index.js');
124- console.log('ESM dist import successful');
125-
126- // Verify basic structure
127- if (typeof pkg === 'object' && pkg !== null) {
128- const exportKeys = Object.keys(pkg);
129- console.log('Package exports found:', exportKeys.length, 'exports');
130-
131- // Check for expected exports
132- const expectedExports = ['SDK_VERSION', 'SDK_NAME', 'getFileTokenScores', 'setWasmDir'];
133- const foundExports = expectedExports.filter(exp => exp in pkg);
134-
135- if (foundExports.length >= 2) {
136- console.log('✅ ESM dist has expected exports:', foundExports.join(', '));
137- process.exit(0);
138- } else {
139- console.error('❌ Missing expected exports. Found:', foundExports.join(', '));
140- process.exit(1);
141- }
142- } else {
143- console.error('❌ Package is not an object:', typeof pkg);
144- process.exit(1);
145- }
146- } catch (error) {
147- console.error('❌ ESM dist import failed:', error.message);
148- process.exit(1);
149- }
150- `
151-
152- writeFileSync ( testFile , testCode )
153-
154- try {
155- execSync ( `node test-esm-dist.mjs` , { stdio : 'pipe' , cwd : testDir } )
156- testResults . push ( { format : 'ESM' , test : 'Basic Import' , success : true } )
157- } catch ( error : any ) {
158- testResults . push ( {
159- format : 'ESM' ,
160- test : 'Basic Import' ,
161- success : false ,
162- error : error . message || 'Unknown error' ,
163- } )
164- }
165- }
166-
167110async function testCJSDist ( ) {
168111 console . log ( ' Testing CJS dist require with Node.js...' )
169112
170113 const testFile = join ( testDir , 'test-cjs-dist.cjs' )
171114 const testCode = `
172115try {
173116 // Require from the built CJS dist files
174- const pkg = require('../dist/cjs/ index.js');
117+ const pkg = require('../dist/index.js');
175118 console.log('CJS dist require successful');
176119
177120 // Verify basic structure
@@ -215,85 +158,6 @@ try {
215158 }
216159}
217160
218- async function testESMTreeSitter ( ) {
219- console . log ( ' Testing ESM dist tree-sitter functionality...' )
220-
221- const testFile = join ( testDir , 'test-esm-treesitter.mjs' )
222- const testCode = `
223- try {
224- // Import tree-sitter functionality from built ESM dist
225- const { getFileTokenScores, setWasmDir } = await import('../dist/esm/index.js');
226- console.log('ESM tree-sitter imports successful');
227-
228- // Set WASM directory to the correct location for dist tests
229- const path = await import('path');
230- const { fileURLToPath } = await import('url');
231-
232- // Set WASM directory to the built dist location
233- setWasmDir(path.join(process.cwd(), '..', 'dist', 'esm', 'wasm'));
234- console.log('✅ setWasmDir function works');
235-
236- // Test getFileTokenScores with sample TypeScript code
237- const projectFiles = {
238- 'test.ts': \`${ sampleCode . replace ( / ` / g, '\\`' ) } \`
239- };
240-
241- const tokenData = await getFileTokenScores(
242- process.cwd(),
243- ['test.ts'],
244- (filePath) => projectFiles[filePath] || null
245- );
246-
247- const { tokenScores } = tokenData;
248-
249- if (!tokenScores['test.ts']) {
250- throw new Error('No token scores found for test.ts');
251- }
252-
253- const tokens = Object.keys(tokenScores['test.ts']);
254- console.log(\`✅ Found \${tokens.length} tokens in TypeScript file\`);
255-
256- // Check for expected tokens
257- const expectedTokens = ['calculateSum', 'Calculator', 'add', 'getHistory'];
258- const foundTokens = expectedTokens.filter(token => tokens.includes(token));
259-
260- if (foundTokens.length > 0) {
261- console.log(\`✅ Found expected tokens: \${foundTokens.join(', ')}\`);
262- process.exit(0);
263- } else {
264- console.warn('⚠ Warning: No expected tokens found. Found tokens:', tokens.slice(0, 10));
265- process.exit(1);
266- }
267-
268- } catch (error) {
269- console.error('❌ ESM tree-sitter test failed:', error.message);
270- process.exit(1);
271- }
272- `
273-
274- writeFileSync ( testFile , testCode )
275-
276- try {
277- const result = execSync ( `node test-esm-treesitter.mjs` , {
278- stdio : 'pipe' ,
279- cwd : testDir ,
280- timeout : 30000 ,
281- encoding : 'utf8'
282- } )
283- console . log ( 'ESM TreeSitter test output:' , result )
284- testResults . push ( { format : 'ESM' , test : 'Tree-sitter' , success : true } )
285- } catch ( error : any ) {
286- console . log ( 'ESM TreeSitter test stderr:' , error . stderr )
287- console . log ( 'ESM TreeSitter test stdout:' , error . stdout )
288- testResults . push ( {
289- format : 'ESM' ,
290- test : 'Tree-sitter' ,
291- success : false ,
292- error : error . message || 'Unknown error' ,
293- } )
294- }
295- }
296-
297161async function testCJSTreeSitter ( ) {
298162 console . log ( ' Testing CJS dist tree-sitter functionality...' )
299163
@@ -302,14 +166,14 @@ async function testCJSTreeSitter() {
302166const runTest = async () => {
303167 try {
304168 // Require tree-sitter functionality from built CJS dist
305- const { getFileTokenScores, setWasmDir } = require('../dist/cjs/ index.js');
169+ const { getFileTokenScores, setWasmDir } = require('../dist/index.js');
306170 console.log('CJS tree-sitter imports successful');
307171
308172 // Set WASM directory to the correct location for dist tests
309173 const path = require('path');
310174
311175 // Set WASM directory to the built dist location
312- setWasmDir(path.join(process.cwd(), '..', 'dist', 'cjs', ' wasm'));
176+ setWasmDir(path.join(process.cwd(), '..', 'dist', 'wasm'));
313177 console.log('✅ setWasmDir function works');
314178
315179 // Test getFileTokenScores with sample TypeScript code
@@ -360,7 +224,7 @@ runTest();
360224 stdio : 'pipe' ,
361225 cwd : testDir ,
362226 timeout : 30000 ,
363- encoding : 'utf8'
227+ encoding : 'utf8' ,
364228 } )
365229 console . log ( 'CJS TreeSitter test output:' , result )
366230 testResults . push ( { format : 'CJS' , test : 'Tree-sitter' , success : true } )
0 commit comments