Skip to content
Snippets Groups Projects
Commit b72f5e63 authored by Simon Malesys's avatar Simon Malesys
Browse files

Add unit tests

parent dc4b6311
Branches
No related tags found
No related merge requests found
Pipeline #156080 passed
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"start": "node src/server/app.js", "start": "node src/server/app.js",
"test": "node --test",
"dev": "concurrently -n Client,Server -c '#325D79,#45ADA8' 'npm:dev:client' 'npm:dev:server'", "dev": "concurrently -n Client,Server -c '#325D79,#45ADA8' 'npm:dev:client' 'npm:dev:server'",
"dev:client": "vite", "dev:client": "vite",
"dev:server": "nodemon --use-strict src/server/app.js | pino-pretty -t 'yyyy-mm-dd HH:MM:ss'", "dev:server": "nodemon --use-strict src/server/app.js | pino-pretty -t 'yyyy-mm-dd HH:MM:ss'",
......
// ABSD
// Copyright (C) 2025 Institut Pasteur
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import { describe, it } from "node:test"
import { ParseFastaStream } from "./ParseFastaStream.js"
import { PassThrough } from "node:stream"
import assert from "node:assert"
describe('ParseFastaStream', () => {
it('should be in object mode by default', () => {
const parser = new ParseFastaStream()
assert(
parser.readableObjectMode === true,
'The objectMode parameter should be true by default'
)
})
it('should transform a raw fasta entry into an object', (test, done) => {
const inputData = 'this is the header\nTHISISTHESEQUENCE'
const expected = {
header: 'this is the header',
sequence: 'THISISTHESEQUENCE'
}
// Setup a test pipeline with mock-up streams
const inputStream = new PassThrough({ objectMode: true })
const outputStream = new PassThrough({ objectMode: true })
const parser = new ParseFastaStream()
inputStream.pipe(parser).pipe(outputStream)
// Handle processed data on the output stream
let outputData = ''
outputStream.on('data', (chunk) => {
outputData = chunk
})
// Assert at the end of the stream
outputStream.on('end', () => {
assert.deepStrictEqual(outputData, expected)
done()
})
// Start the process
inputStream.write(inputData)
inputStream.end()
})
})
// ABSD
// Copyright (C) 2025 Institut Pasteur
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import { describe, it } from "node:test"
import { SanitizeFastaStream } from "./SanitizeFastaStream.js"
import { PassThrough } from "node:stream"
import assert from "node:assert"
describe('SanitizeFastaStream', () => {
it('should be in object mode by default', () => {
const parser = new SanitizeFastaStream()
assert(
parser.readableObjectMode === true,
'The objectMode parameter should be true by default'
)
})
it('should remove extra spaces and tabs from a fasta object', (test, done) => {
const inputData = {
header: 'this is \t the header\t',
sequence: ' THISISTHESEQUENCE '
}
const expected = {
header: 'this is the header',
sequence: 'THISISTHESEQUENCE'
}
// Setup a test pipeline with mock-up streams
const inputStream = new PassThrough({ objectMode: true })
const outputStream = new PassThrough({ objectMode: true })
const parser = new SanitizeFastaStream()
inputStream.pipe(parser).pipe(outputStream)
// Handle processed data on the output stream
let outputData = ''
outputStream.on('data', (chunk) => {
outputData = chunk
})
// Assert at the end of the stream
outputStream.on('end', () => {
assert.deepStrictEqual(outputData, expected)
done()
})
// Start the process
inputStream.write(inputData)
inputStream.end()
})
})
// ABSD
// Copyright (C) 2025 Institut Pasteur
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import { describe, it } from "node:test"
import { SplitFastaStream } from "./SplitFastaStream.js"
import { PassThrough } from "node:stream"
import assert from "node:assert"
describe('SplitFastaStream', () => {
it('should be in object mode by default', () => {
const splitFasta = new SplitFastaStream()
assert(
splitFasta.readableObjectMode === true,
'The objectMode parameter should be true by default'
)
})
it('should have a buffer property, intialized as an empty string', () => {
const splitFasta = new SplitFastaStream()
assert(
splitFasta.buffer === '',
'The buffer property needs to be set'
)
})
it('should have a firstLine property, intialized to true', () => {
const splitFasta = new SplitFastaStream()
assert(
splitFasta.firstLine === true,
'The firstLine property needs to be set'
)
})
it('should decode and split a buffer into a series of raw fasta, sent one by one', (test, done) => {
const inputData = new Buffer.from(
'>First header\nFIRSTSEQUENCE\n' +
'>Second header\nSECONDSEQUENCE\n' +
'>Third header\nTHIRDSEQUENCE\n'
)
const expected = [
'First header\nFIRSTSEQUENCE\n',
'Second header\nSECONDSEQUENCE\n',
'Third header\nTHIRDSEQUENCE\n'
]
// Setup a test pipeline with mock-up streams
const inputStream = new PassThrough()
const outputStream = new PassThrough({ objectMode: true })
const splitFasta = new SplitFastaStream()
inputStream.pipe(splitFasta).pipe(outputStream)
// Handle processed data on the output stream
let outputData = []
outputStream.on('data', (chunk) => {
outputData.push(chunk)
})
// Assert at the end of the stream
outputStream.on('end', () => {
assert.deepStrictEqual(outputData, expected)
done()
})
// Start the process
inputStream.write(inputData)
inputStream.end()
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment