All files / test reader-test.ts

100% Statements 32/32
100% Branches 0/0
100% Functions 8/8
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51  1x 1x 1x   1x 1x 1x   1x 1x   1x 1x 1x 1x 1x 1x 1x   1x 1x   1x 1x     1x   1x   1x   1x 1x 1x   1x     1x 1x 1x   1x 1x 1x        
import assert from "mocha";
import chai from "chai";
import chaiAsPromised from "chai-as-promised";
import { Reader, INVALID_FILE } from "../lib/reader/reader";
import { copyFileAsync } from "../lib/reader/utils";
import { loadXml } from "../lib/reader/xml";
import { copySync, remove } from "fs-extra";
import path from "path";
 
chai.use(chaiAsPromised);
chai.should();
 
const sample_als = "sample-project Project/sample-project.als";
const manual_als = "test.als";
const manual_xml = "test.xml"
const invalid_file = "invalid-file";
const test_res = "./test/res";
const test_tmp = "./test/tmp";
const expect = chai.expect;
 
describe('Reader', function() {
    describe ('Load Reader', function() {
        // TODO: Put proper analutics to check how slow?
        this.slow(100);
        before(function() {
            // Create a copy of the sample files.
            // This is important as the parser modifies the origional file.
            copySync(test_res, test_tmp)
        });
        after(function() {
            // Cleanup after test
            remove(test_tmp)
        });
        it('When the valid gzipped als is given', function(done) {
            loadXml(path.join(test_tmp, manual_xml)).then(function (expected_xml) {
                let reader = new Reader(path.join(test_tmp, manual_als));
                // eql is used instead of equal as the objects are not directly comparable
                reader.load().should.eventually.eql(expected_xml).notify(done);
            })
        });
        it('When the invalid file type is given', function(done) {
            let reader = new Reader(path.join(test_tmp, "invalid-file"));
            reader.load().should.eventually.rejectedWith(INVALID_FILE).notify(done);
        });
        it('When the valid extracted(xml) als is given', function(done) {
            expect('Hello World').to.equal('Hello World');
            done();
        });
    });
});