fix(test): replace meaningless assertions and silent skips with proper test semantics

- Replace 4x expect(true).toBe(true) in audit-logger.test.ts with
  applyAuditConfig() + app.getVersion call count assertions
- Replace if(!hasCredentials){return} pattern with it.skipIf() in
  3 integration test files (cleaner, erp-auth, extractor) so Vitest
  correctly reports 12 tests as "skipped" instead of "passed"
- Remove placeholder assertion from skipped update-service test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-04-04 21:11:12 +08:00
parent 5d8563a4c9
commit d7ebb10f38
5 changed files with 93 additions and 145 deletions

View File

@@ -21,12 +21,7 @@ describe('Cleaner Service (Integration)', () => {
const hasCredentials = !!(config.url && config.username && config.password)
describe('Dry-run mode', () => {
it('should initialize with dry-run mode', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)('should initialize with dry-run mode', async () => {
const authService = new ErpAuthService(config)
await authService.login()
@@ -37,64 +32,58 @@ describe('Cleaner Service (Integration)', () => {
await authService.close()
}, 30000)
it('should track materials to delete without actually deleting (dry-run)', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)(
'should track materials to delete without actually deleting (dry-run)',
async () => {
const authService = new ErpAuthService(config)
await authService.login()
const authService = new ErpAuthService(config)
await authService.login()
// Read test data
const orderContent = await fs.readFile(productionIdFile, 'utf-8')
const orderNumbers = orderContent
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0)
.slice(0, 2) // Test first 2 orders
// Read test data
const orderContent = await fs.readFile(productionIdFile, 'utf-8')
const orderNumbers = orderContent
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0)
.slice(0, 2) // Test first 2 orders
const materialContent = await fs.readFile(materialCodeFile, 'utf-8')
const materialCodes = materialContent
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0)
const materialContent = await fs.readFile(materialCodeFile, 'utf-8')
const materialCodes = materialContent
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0)
console.log(
`Testing dry-run with ${orderNumbers.length} orders and ${materialCodes.length} material codes`
)
console.log(
`Testing dry-run with ${orderNumbers.length} orders and ${materialCodes.length} material codes`
)
const cleaner = new CleanerService(authService, { dryRun: true })
const cleaner = new CleanerService(authService, { dryRun: true })
const result = await cleaner.clean({
orderNumbers,
materialCodes,
dryRun: true
})
const result = await cleaner.clean({
orderNumbers,
materialCodes,
dryRun: true
})
// In dry-run mode, materialsDeleted should be tracked but not actually deleted
console.log(`Dry-run result:`, {
ordersProcessed: result.ordersProcessed,
materialsDeleted: result.materialsDeleted,
materialsSkipped: result.materialsSkipped,
errors: result.errors.length
})
// In dry-run mode, materialsDeleted should be tracked but not actually deleted
console.log(`Dry-run result:`, {
ordersProcessed: result.ordersProcessed,
materialsDeleted: result.materialsDeleted,
materialsSkipped: result.materialsSkipped,
errors: result.errors.length
})
expect(result.ordersProcessed).toBeGreaterThan(0)
// In dry-run, no actual deletions should happen
expect(result.errors).toHaveLength(0)
expect(result.ordersProcessed).toBeGreaterThan(0)
// In dry-run, no actual deletions should happen
expect(result.errors).toHaveLength(0)
await authService.close()
}, 120000)
await authService.close()
},
120000
)
})
describe('Order processing', () => {
it('should process single order and return details', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)('should process single order and return details', async () => {
const authService = new ErpAuthService(config)
await authService.login()
@@ -120,12 +109,7 @@ describe('Cleaner Service (Integration)', () => {
await authService.close()
}, 60000)
it('should handle order with "审批通过" status', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)('should handle order with "审批通过" status', async () => {
const authService = new ErpAuthService(config)
await authService.login()
@@ -155,12 +139,7 @@ describe('Cleaner Service (Integration)', () => {
await authService.close()
}, 60000)
it('should handle multiple orders with progress callback', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)('should handle multiple orders with progress callback', async () => {
const authService = new ErpAuthService(config)
await authService.login()
@@ -194,12 +173,7 @@ describe('Cleaner Service (Integration)', () => {
})
describe('Error handling', () => {
it('should continue processing after order error', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)('should continue processing after order error', async () => {
const authService = new ErpAuthService(config)
await authService.login()
@@ -221,27 +195,26 @@ describe('Cleaner Service (Integration)', () => {
})
describe('Navigation', () => {
it('should navigate to discrete production order maintenance page', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)(
'should navigate to discrete production order maintenance page',
async () => {
const authService = new ErpAuthService(config)
await authService.login()
const authService = new ErpAuthService(config)
await authService.login()
const cleaner = new CleanerService(authService, { dryRun: true })
const cleaner = new CleanerService(authService, { dryRun: true })
// This tests the internal navigation method
const session = authService.getSession()
const { popupPage, workFrame } = await cleaner.navigateToCleanerPage(session)
// This tests the internal navigation method
const session = authService.getSession()
const { popupPage, workFrame } = await cleaner.navigateToCleanerPage(session)
expect(popupPage).toBeDefined()
expect(workFrame).toBeDefined()
expect(popupPage).toBeDefined()
expect(workFrame).toBeDefined()
// Cleanup
await popupPage.close()
await authService.close()
}, 60000)
// Cleanup
await popupPage.close()
await authService.close()
},
60000
)
})
})

View File

@@ -15,19 +15,11 @@ describe('ERP Authentication Service (Integration)', () => {
const hasCredentials = !!(config.url && config.username && config.password)
beforeAll(() => {
if (!hasCredentials) {
console.warn('Skipping ERP auth tests: credentials not configured')
return
}
if (!hasCredentials) return
authService = new ErpAuthService(config)
})
it('should login successfully', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)('should login successfully', async () => {
const session = await authService.login()
expect(session).toBeDefined()
@@ -37,12 +29,7 @@ describe('ERP Authentication Service (Integration)', () => {
expect(session.isLoggedIn).toBe(true)
}, 30000)
it('should navigate to main page after login', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)('should navigate to main page after login', async () => {
const session = await authService.login()
const url = session.page.url()

View File

@@ -1,4 +1,4 @@
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
import { describe, it, expect } from 'vitest'
import { ExtractorService } from '../../src/main/services/erp/extractor'
import { ErpAuthService } from '../../src/main/services/erp/erp-auth'
import type { ErpConfig } from '../../src/main/types/erp.types'
@@ -18,12 +18,7 @@ describe('Extractor Service (Integration)', () => {
// Check if we have ERP credentials
const hasCredentials = !!(config.url && config.username && config.password)
it('should extract data for single order number', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)('should extract data for single order number', async () => {
// Create fresh auth service for this test
const authService = new ErpAuthService(config)
await authService.login()
@@ -46,12 +41,7 @@ describe('Extractor Service (Integration)', () => {
await authService.close()
}, 60000)
it('should extract data for multiple order numbers', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)('should extract data for multiple order numbers', async () => {
// Create fresh auth service for this test
const authService = new ErpAuthService(config)
await authService.login()
@@ -59,10 +49,6 @@ describe('Extractor Service (Integration)', () => {
const extractor = new ExtractorService(authService)
// Read order numbers from productionID.txt file
const fs = await import('fs/promises')
const path = await import('path')
// productionID.txt is at: D:\FileLib\Projects\CodeMigration\references\demo\productionID.txt
// test runs at: D:\FileLib\Projects\CodeMigration\ERPAuto
const productionIdFile = path.join(process.cwd(), '../references/demo/productionID.txt')
const content = await fs.readFile(productionIdFile, 'utf-8')
const orderNumbers = content
@@ -89,12 +75,7 @@ describe('Extractor Service (Integration)', () => {
await authService.close()
}, 120000) // Increase timeout to 2 minutes
it('should extract data for 300 orders with batch size 70', async () => {
if (!hasCredentials) {
console.warn('Skipping test: ERP credentials not configured')
return
}
it.skipIf(!hasCredentials)('should extract data for 300 orders with batch size 70', async () => {
// Create fresh auth service for this test
const authService = new ErpAuthService(config)
await authService.login()
@@ -102,8 +83,6 @@ describe('Extractor Service (Integration)', () => {
const extractor = new ExtractorService(authService)
// Read all order numbers from productionID.txt file
const fs = await import('fs/promises')
const path = await import('path')
const productionIdFile = path.join(process.cwd(), '../references/demo/productionID.txt')
const content = await fs.readFile(productionIdFile, 'utf-8')
const orderNumbers = content
@@ -130,7 +109,9 @@ describe('Extractor Service (Integration)', () => {
console.log(`Expected batches: ${Math.ceil(orderNumbers.length / 70)}`)
console.log(`Downloaded files: ${result.downloadedFiles.length}`)
console.log(`Total duration: ${duration}s`)
console.log(`Average time per batch: ${(duration / result.downloadedFiles.length).toFixed(2)}s`)
console.log(
`Average time per batch: ${(duration / result.downloadedFiles.length).toFixed(2)}s`
)
if (result.errors.length > 0) {
console.log(`\nErrors encountered: ${result.errors.length}`)