|
|
@@ -0,0 +1,76 @@
|
|
|
+/* eslint-env node */
|
|
|
+const fs = require('fs')
|
|
|
+const os = require('os')
|
|
|
+const path = require('path')
|
|
|
+const assert = require('assert')
|
|
|
+const crypto = require('crypto')
|
|
|
+const { spawnSync } = require('child_process')
|
|
|
+const output = fs.mkdtempSync(path.join(os.tmpdir(), 'ng-welcome-pricing-'))
|
|
|
+const target = path.resolve(__dirname, '../MemberWelcomePack.vue')
|
|
|
+const original = fs.readFileSync(target, 'utf8')
|
|
|
+const jest = 'node_modules/jest/bin/jest.js'
|
|
|
+const pricingTests = 'uses member price|matches the member card|accepts cash balance|recalculates multiple member'
|
|
|
+function run(args, name) {
|
|
|
+ const result = spawnSync(process.execPath, args, {
|
|
|
+ encoding: 'utf8', env: { ...process.env, NODE_OPTIONS: '--openssl-legacy-provider' }
|
|
|
+ })
|
|
|
+ fs.writeFileSync(path.join(output, name + '.log'), (result.stdout || '') + (result.stderr || ''))
|
|
|
+ assert(!result.error && result.status !== null, 'Runner failed: ' + name)
|
|
|
+ return result
|
|
|
+}
|
|
|
+function assertKilled(result, report) {
|
|
|
+ assert.strictEqual(result.status, 1, 'Mutation did not fail')
|
|
|
+ assert(report.numFailedTests > 0 && report.numRuntimeErrorTestSuites === 0, 'Expected test assertions, not runner errors')
|
|
|
+}
|
|
|
+assert.throws(() => assertKilled({ status: 0 }, { numFailedTests: 0 }))
|
|
|
+assert.throws(() => assertKilled({ status: 1 }, { numFailedTests: 0, numRuntimeErrorTestSuites: 1 }))
|
|
|
+const mutations = [
|
|
|
+ ['subtotal', 'subtotal += Number(item.SELL_PRICE)', 'subtotal += Number(item.MARKET_PRICE)'],
|
|
|
+ ['tax', 'tax += tool.calculateTax(Number(item.SELL_PRICE)', 'tax += tool.calculateTax(Number(item.MARKET_PRICE)'],
|
|
|
+ ['balance', 'this.payAmount += Number(item.SELL_PRICE)', 'this.payAmount += Number(item.MARKET_PRICE)'],
|
|
|
+ ['details', 'tool.calculateTax(Number(row.SELL_PRICE)', 'tool.calculateTax(Number(row.MARKET_PRICE)']
|
|
|
+]
|
|
|
+for (const [name, from, to] of mutations) {
|
|
|
+ assert.strictEqual(original.split(from).length, 2, 'Mutation target must be unique: ' + name)
|
|
|
+ const report = path.join(output, name + '.json')
|
|
|
+ try {
|
|
|
+ fs.writeFileSync(target, original.replace(from, to))
|
|
|
+ const result = run([jest, '--runInBand', '--testMatch', '**/welcome-pack/__tests__/MemberWelcomePack.spec.js', '--testNamePattern', pricingTests, '--json', '--outputFile=' + report], name)
|
|
|
+ assertKilled(result, JSON.parse(fs.readFileSync(report, 'utf8')))
|
|
|
+ console.log('Killed: ' + name)
|
|
|
+ } finally {
|
|
|
+ fs.writeFileSync(target, original)
|
|
|
+ assert.strictEqual(fs.readFileSync(target, 'utf8'), original)
|
|
|
+ }
|
|
|
+}
|
|
|
+const baseline = [
|
|
|
+ ...['repeat-purchase', 'member-repurchase', 'member-auto-maintenance', 'member-upgrade'].map(name => name + ' shows checkout product prices and BV using the existing purchase rules'),
|
|
|
+ ...['repeat-purchase', 'member-repurchase', 'member-auto-maintenance', 'member-upgrade'].map(name => 'keeps the order list fallback when ' + name + ' returns no order number'),
|
|
|
+ 'renders the confirmed order/goods response with an empty goods list and missing address',
|
|
|
+ 'Profile UI preserves existing account, password and address behavior preserves edit row mapping, ID and default string values without changing other card actions',
|
|
|
+ 'inherits each old page without replacing its state, requests, downloads or amount filters',
|
|
|
+ 'loads only the selected endpoint and displays multiple orders, all details and products',
|
|
|
+ 'keeps separate pagination when switching categories and does not duplicate requests on return',
|
|
|
+ 'summarizes each order separately using the existing displayed quantity, price, BV and tax',
|
|
|
+ 'Sponsor Network UI reuses both original network scripts keeps the original untrimmed username, unrestricted depth and period query on form submission',
|
|
|
+ 'AccountBalances preserves the existing account logic resets page size to the original 5 and repeats the same request',
|
|
|
+ 'Team inquiry UI and its account shortcut opens Repeat Purchase from Browse products while preserving the current query',
|
|
|
+ 'new page theme preserves Element UI and legacy pages retains control geometry and confines table styles to new pages'
|
|
|
+].sort()
|
|
|
+const checkFailures = failures => assert.deepStrictEqual(failures.slice().sort(), baseline, 'Failures changed from the recorded pre-change baseline')
|
|
|
+assert.throws(() => checkFailures(baseline.concat('Unexpected failure')))
|
|
|
+const report = path.join(output, 'regression.json')
|
|
|
+const regression = run(['--max-old-space-size=8192', jest, '--runInBand', '--testMatch', '**/__tests__/*.spec.js', '**/tests/unit/**/*.spec.js', '--json', '--outputFile=' + report, '--silent'], 'regression')
|
|
|
+assert.strictEqual(regression.status, 1)
|
|
|
+const tests = JSON.parse(fs.readFileSync(report, 'utf8'))
|
|
|
+const failures = tests.testResults.flatMap(suite => suite.assertionResults.filter(test => test.status === 'failed').map(test => test.fullName))
|
|
|
+checkFailures(failures)
|
|
|
+const suiteErrors = tests.testResults.filter(suite => suite.status === 'failed' && !suite.assertionResults.length)
|
|
|
+assert.deepStrictEqual(suiteErrors.map(suite => path.relative(process.cwd(), suite.name).replace(/\\/g, '/')).sort(), ['tests/unit/components/Hamburger.spec.js', 'tests/unit/components/SvgIcon.spec.js'])
|
|
|
+assert(suiteErrors.every(suite => suite.message.includes('Vue packages version mismatch')))
|
|
|
+assert.strictEqual(run(['node_modules/eslint/bin/eslint.js', '--max-warnings=0', target, path.join(__dirname, 'MemberWelcomePack.spec.js'), __filename], 'lint').status, 0)
|
|
|
+assert.strictEqual(run(['node_modules/@vue/cli-service/bin/vue-cli-service.js', 'build', '--dest', path.join(output, 'build'), '--no-clean'], 'build').status, 0)
|
|
|
+assert.strictEqual(fs.readFileSync(target, 'utf8'), original)
|
|
|
+const result = { passed: tests.numPassedTests, existingFailures: failures.length, existingCompilerErrors: suiteErrors.length, mutationsKilled: mutations.length, lint: 'passed', build: 'passed', sourceHash: crypto.createHash('sha256').update(original).digest('hex'), output }
|
|
|
+fs.writeFileSync(path.join(output, 'result.json'), JSON.stringify(result, null, 2))
|
|
|
+console.log(JSON.stringify(result, null, 2))
|