quotationPackageBoundary.test.mjs 1.41 KB
import assert from 'node:assert/strict'
import { readFileSync, readdirSync, statSync } from 'node:fs'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'

const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
const quotationRoot = path.join(projectRoot, 'packageEquity/pages/carQuotation')

function listSourceFiles(directory) {
  return readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
    const target = path.join(directory, entry.name)
    if (entry.isDirectory()) return listSourceFiles(target)
    return /\.(?:js|json|wxml|wxs)$/.test(entry.name) && statSync(target).isFile()
      ? [target]
      : []
  })
}

test('quotation sources do not import another business subpackage', () => {
  for (const filePath of listSourceFiles(quotationRoot)) {
    const source = readFileSync(filePath, 'utf8')
    assert.doesNotMatch(source, /~\/(?:tabWorkOrder|packageUsedCar|packageDynamicForm)\//, filePath)
    assert.doesNotMatch(source, /(?:\.\.\/)+(?:tabWorkOrder|packageUsedCar|packageDynamicForm)\//, filePath)
  }
})

test('reusable simple quotation product strategy is not owned by the page directory', () => {
  const componentPath = path.join(
    quotationRoot,
    'components/SecondStepSimple/SecondStep.js'
  )
  assert.doesNotMatch(
    readFileSync(componentPath, 'utf8'),
    /createOrderCarQuotationSimple\/productStrategy/
  )
})