Added scanning barcodes with a camera

This commit is contained in:
2026-03-08 16:59:33 +00:00
parent b4f8489834
commit 5a37e5dd5f
404 changed files with 224181 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
import Quagga from '../../../src/quagga';
import { expect } from 'chai';
import { it } from '../helpers';
describe('EAN Supplement Format Tests', () => {
// Test that verifies the supplement format is correctly returned as 'ean_2' or 'ean_5'
// rather than inheriting the parent 'ean_13' format
const isBrowser = typeof window !== 'undefined';
const fixturePrefix = isBrowser ? '/' : '';
const baseConfig = {
inputStream: {
size: 800,
singleChannel: false,
},
locator: {
patchSize: 'medium' as const,
halfSample: false,
},
numOfWorkers: 0,
decoder: {
readers: [{
format: 'ean_reader',
config: {
supplements: [
'ean_5_reader',
'ean_2_reader',
],
},
}],
},
};
it('should return ean_2 format for 2-digit supplement', async function() {
this.timeout(30000);
const config = {
...baseConfig,
src: `${fixturePrefix}test/fixtures/ean_extended/image-002.jpg`, // EAN-13 with 2-digit supplement
};
const result = await Quagga.decodeSingle(config);
expect(result).to.be.an('Object');
expect(result.codeResult).to.be.an('Object');
expect(result.codeResult.format).to.equal('ean_13');
expect(result.codeResult.supplement).to.be.an('Object');
expect(result.codeResult.supplement.format).to.equal('ean_2');
expect(result.codeResult.supplement.code).to.equal('01');
});
it('should return ean_5 format for 5-digit supplement', async function() {
this.timeout(30000);
const config = {
...baseConfig,
src: `${fixturePrefix}test/fixtures/ean_extended/image-004.jpg`, // EAN-13 with 5-digit supplement
};
const result = await Quagga.decodeSingle(config);
expect(result).to.be.an('Object');
expect(result.codeResult).to.be.an('Object');
expect(result.codeResult.format).to.equal('ean_13');
expect(result.codeResult.supplement).to.be.an('Object');
expect(result.codeResult.supplement.format).to.equal('ean_5');
expect(result.codeResult.supplement.code).to.equal('52495');
});
});