Initial commit: Epson ePOS Node backend + Vue3 UI (printer matricial2)
This commit is contained in:
14
scripts/tests/01_text_simple.js
Normal file
14
scripts/tests/01_text_simple.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const { post, ensureOk } = require('./common');
|
||||
|
||||
async function run() {
|
||||
const data = await post('/api/print/text', { text: 'Test 1: texto simple', options: { feedLines: 1 } });
|
||||
console.log('01_text_simple ->', data);
|
||||
ensureOk(data, '01_text_simple');
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
run().catch((e) => { console.error(e.message); process.exit(1); });
|
||||
}
|
||||
|
||||
module.exports = run;
|
||||
|
||||
14
scripts/tests/02_align_cut.js
Normal file
14
scripts/tests/02_align_cut.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const { post, ensureOk } = require('./common');
|
||||
|
||||
async function run() {
|
||||
const data = await post('/api/print/text', { text: 'Test 2: center + cut', options: { align: 'center', feedLines: 1, cut: 'feed' } });
|
||||
console.log('02_align_cut ->', data);
|
||||
ensureOk(data, '02_align_cut');
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
run().catch((e) => { console.error(e.message); process.exit(1); });
|
||||
}
|
||||
|
||||
module.exports = run;
|
||||
|
||||
17
scripts/tests/03_font_size.js
Normal file
17
scripts/tests/03_font_size.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const { post, ensureOk } = require('./common');
|
||||
|
||||
async function run() {
|
||||
const data = await post('/api/print/text', {
|
||||
text: 'Test 3: font_b w2 h2',
|
||||
options: { font: 'font_b', size: { width: 2, height: 2 }, style: { em: true }, feedLines: 1 }
|
||||
});
|
||||
console.log('03_font_size ->', data);
|
||||
ensureOk(data, '03_font_size');
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
run().catch((e) => { console.error(e.message); process.exit(1); });
|
||||
}
|
||||
|
||||
module.exports = run;
|
||||
|
||||
21
scripts/tests/04_batch_feeds.js
Normal file
21
scripts/tests/04_batch_feeds.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const { post, ensureOk } = require('./common');
|
||||
|
||||
async function run() {
|
||||
const data = await post('/api/print', {
|
||||
operations: [
|
||||
{ op: 'text', value: 'Test 4: linea 1' },
|
||||
{ op: 'feedLine', line: 1 },
|
||||
{ op: 'text', value: 'Test 4: linea 2' },
|
||||
{ op: 'feedLine', line: 1 }
|
||||
]
|
||||
});
|
||||
console.log('04_batch_feeds ->', data);
|
||||
ensureOk(data, '04_batch_feeds');
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
run().catch((e) => { console.error(e.message); process.exit(1); });
|
||||
}
|
||||
|
||||
module.exports = run;
|
||||
|
||||
22
scripts/tests/05_barcode.js
Normal file
22
scripts/tests/05_barcode.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const { post, ensureOk } = require('./common');
|
||||
|
||||
async function run() {
|
||||
const data = await post('/api/print', {
|
||||
operations: [
|
||||
{ op: 'textAlign', align: 'center' },
|
||||
{ op: 'text', value: 'Test 5: EAN13' },
|
||||
{ op: 'feedLine', line: 1 },
|
||||
{ op: 'barcode', data: '490123456789', type: 'ean13', hri: 'below', width: 3, height: 80 },
|
||||
{ op: 'feedLine', line: 2 }
|
||||
]
|
||||
});
|
||||
console.log('05_barcode ->', data);
|
||||
ensureOk(data, '05_barcode');
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
run().catch((e) => { console.error(e.message); process.exit(1); });
|
||||
}
|
||||
|
||||
module.exports = run;
|
||||
|
||||
22
scripts/tests/06_qr.js
Normal file
22
scripts/tests/06_qr.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const { post, ensureOk } = require('./common');
|
||||
|
||||
async function run() {
|
||||
const data = await post('/api/print', {
|
||||
operations: [
|
||||
{ op: 'textAlign', align: 'center' },
|
||||
{ op: 'text', value: 'Test 6: QR' },
|
||||
{ op: 'feedLine', line: 1 },
|
||||
{ op: 'qrcode', data: 'https://example.com/test6', model: 'qrcode_model_2', level: 'level_m', size: 6 },
|
||||
{ op: 'feedLine', line: 2 }
|
||||
]
|
||||
});
|
||||
console.log('06_qr ->', data);
|
||||
ensureOk(data, '06_qr');
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
run().catch((e) => { console.error(e.message); process.exit(1); });
|
||||
}
|
||||
|
||||
module.exports = run;
|
||||
|
||||
14
scripts/tests/07_pulse.js
Normal file
14
scripts/tests/07_pulse.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const { post, ensureOk } = require('./common');
|
||||
|
||||
async function run() {
|
||||
const data = await post('/api/print/pulse', { drawer: 'drawer_1', time: 'pulse_200' });
|
||||
console.log('07_pulse ->', data);
|
||||
ensureOk(data, '07_pulse');
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
run().catch((e) => { console.error(e.message); process.exit(1); });
|
||||
}
|
||||
|
||||
module.exports = run;
|
||||
|
||||
19
scripts/tests/common.js
Normal file
19
scripts/tests/common.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const axios = require('axios');
|
||||
|
||||
const baseURL = process.env.TEST_BASE_URL || 'http://localhost:3000';
|
||||
const client = axios.create({ baseURL, timeout: 120000 });
|
||||
|
||||
async function post(path, body) {
|
||||
const res = await client.post(path, body);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
function ensureOk(data, stepName) {
|
||||
if (!data || data.ok !== true) {
|
||||
const msg = `Printer did not confirm success on step: ${stepName} -> ${JSON.stringify(data)}`;
|
||||
throw new Error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { post, ensureOk };
|
||||
|
||||
Reference in New Issue
Block a user