Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 60 additions & 60 deletions __tests__/aggregate-results.test.js
Original file line number Diff line number Diff line change
@@ -1,150 +1,150 @@
const { getTableTotals } = require("../src/aggregate-results");
const { totalPercentageReducer } = require("../src/helpers/test-helpers");
const {getTableTotals} = require('../src/aggregate-results')
const {totalPercentageReducer} = require('../src/helpers/test-helpers')

test("test getTableTotals", function (done) {
test('test getTableTotals', function (done) {
const mockRunnerResults = [
{
runner: "Test Runner 1",
runner: 'Test Runner 1',
results: {
version: 1,
status: "pass",
status: 'pass',
tests: [
{
name: "Test 1",
status: "pass",
name: 'Test 1',
status: 'pass',
message: null,
line_no: null,
execution_time: "0ms",
execution_time: '0ms',
score: 1,
},
{
name: "Test 2",
status: "fail",
message: "Expected output not matched",
name: 'Test 2',
status: 'fail',
message: 'Expected output not matched',
line_no: 10,
execution_time: "5ms",
execution_time: '5ms',
score: 0,
},
],
max_score: 2,
},
},
{
runner: "Test Runner 2",
runner: 'Test Runner 2',
results: {
version: 2,
status: "fail",
status: 'fail',
tests: [
{
name: "Test 3",
status: "pass",
name: 'Test 3',
status: 'pass',
message: null,
line_no: null,
execution_time: "0ms",
execution_time: '0ms',
score: 1,
},
{
name: "Test 4",
status: "fail",
message: "Expected output not matched",
name: 'Test 4',
status: 'fail',
message: 'Expected output not matched',
line_no: 10,
execution_time: "5ms",
execution_time: '5ms',
score: 0,
},
],
max_score: 2,
},
},
];
]
const mockPushToTable = (row) => {
console.log(row);
};
const result = getTableTotals(mockRunnerResults, mockPushToTable);
console.log(row)
}
const result = getTableTotals(mockRunnerResults, mockPushToTable)
expect(result).toStrictEqual([
{
score: 1,
maxScore: 2,
weight: "50.00",
weight: '50.00',
},
{
score: 1,
maxScore: 2,
weight: "50.00",
weight: '50.00',
},
]);
const totalPercent = result.reduce(totalPercentageReducer, 0);
expect(totalPercent).toBe(50);
])
const totalPercent = result.reduce(totalPercentageReducer, 0)
expect(totalPercent).toBe(50)

done();
});
done()
})

test("test getTableTotals where weight is weird", function (done) {
test('test getTableTotals where weight is weird', function (done) {
const mockRunnerResults = [
{
runner: "Runner 1",
runner: 'Runner 1',
results: {
version: 1,
status: "pass",
status: 'pass',
tests: [
{
name: "Test 1",
status: "pass",
name: 'Test 1',
status: 'pass',
message: null,
line_no: null,
execution_time: "0ms",
execution_time: '0ms',
},
{
name: "Test 2",
status: "fail",
message: "Expected output not matched",
name: 'Test 2',
status: 'fail',
message: 'Expected output not matched',
line_no: 10,
execution_time: "5ms",
execution_time: '5ms',
},
],
max_score: 2.5, // weird max_score
},
},
{
runner: "Runner 2",
runner: 'Runner 2',
results: {
version: 2,
status: "fail",
status: 'fail',
tests: [
{
name: "Test 3",
status: "pass",
name: 'Test 3',
status: 'pass',
message: null,
line_no: null,
execution_time: "0ms",
execution_time: '0ms',
},
{
name: "Test 4",
status: "fail",
message: "Expected output not matched",
name: 'Test 4',
status: 'fail',
message: 'Expected output not matched',
line_no: 10,
execution_time: "5ms",
execution_time: '5ms',
},
],
max_score: 3.3, // weird max_score
},
},
];
]

const mockPushToTable = (row) => {
console.log(row);
};
const result = getTableTotals(mockRunnerResults, mockPushToTable);
console.log(row)
}
const result = getTableTotals(mockRunnerResults, mockPushToTable)
expect(result).toStrictEqual([
{
score: 1.25,
maxScore: 2.5,
weight: "43.00",
weight: '43.00',
},
{
score: 1.65,
maxScore: 3.3,
weight: "57.00",
weight: '57.00',
},
]);
done();
});
])
done()
})
180 changes: 100 additions & 80 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,103 @@
const process = require("process");
const cp = require("child_process");
const path = require("path");
const process = require('process')
const cp = require('child_process')
const path = require('path')

const node = process.execPath;
const ip = path.join(__dirname, "..", "src", "main.js");
const node = process.execPath
const ip = path.join(__dirname, '..', 'src', 'main.js')
const options = {
env: process.env,
encoding: "utf-8",
};

const { parseRunnerResults } = require("../src/main");

test("test runs", () => {
process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }').toString("base64");
process.env.INPUT_RUNNERS = "result1";

const child = cp.spawnSync(node, [ip], options);
const stdout = child.stdout.toString();
expect(stdout).toContain(`✅ Test 1`);
});

test("test fails", () => {
process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "fail", "message": "Test failed with non-zero exit code." }] }').toString("base64");
process.env.INPUT_RUNNERS = "result1";

const child = cp.spawnSync(node, [ip], options);
const stdout = child.stdout.toString();
expect(stdout).toContain(`❌ Test 1`);
});

test("test errors out", () => {
process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "error", "message": "Test failed to execute." }] }').toString("base64");
process.env.INPUT_RUNNERS = "result1";

const child = cp.spawnSync(node, [ip], options);
const stdout = child.stdout.toString();
expect(stdout).toContain(`Error: Test failed to execute.`);
});

test("fails to run if input not in the right format", () => {
process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }').toString("base64");
process.env.RESULT2_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }').toString("base64");
process.env.INPUT_RUNNERS = "[result1,result2]";

const child = cp.spawnSync(node, [ip], options);
const stderr = child.stderr.toString();
expect(stderr).toContain(`The runners input must be a comma-separated list of strings.`);
});

// test('test runs with multiple runners', () => {
// process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }').toString('base64')
// process.env.RESULT2_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }').toString('base64')
// process.env.INPUT_RUNNERS = 'result1,result2'

// const child = cp.spawnSync(node, [ip], options)
// const stdout = child.stdout.toString()
// console.log(stdout)
// expect(stdout).toBe('pass')
// })

// test('test fails with multiple runners', () => {
// process.env.RESULT1_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 1", "status": "fail", "message": null }] }').toString('base64')
// process.env.RESULT2_RESULTS = Buffer.from('{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }').toString('base64')
// process.env.INPUT_RUNNERS = 'result1,result2'

// const child = cp.spawnSync(node, [ip], options)
// const stdout = child.stdout.toString()
// console.log(stdout)
// expect(stdout).toBe('fail')
// })

test("test autograding-output.parseRunnerResults", function () {
process.env.INPUT_RUNNERS = "result1,result2";

let testResults1 = parseRunnerResults(process.env.INPUT_RUNNERS);
expect(testResults1.length).toBe(2);
expect(testResults1[0].runner).toBe("result1");
expect(testResults1[1].runner).toBe("result2");

process.env.INPUT_RUNNERS = "[result1,result2]";
expect(() => parseRunnerResults(process.env.INPUT_RUNNERS)).toThrow("The runners input must be a comma-separated list of strings.");
});
encoding: 'utf-8',
}

const {parseRunnerResults} = require('../src/main')

test('test runs', () => {
process.env.RESULT1_RESULTS = Buffer.from(
'{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }',
).toString('base64')
process.env.INPUT_RUNNERS = 'result1'

const child = cp.spawnSync(node, [ip], options)
const stdout = child.stdout.toString()
expect(stdout).toContain(`✅ Test 1`)
})

test('test fails', () => {
process.env.RESULT1_RESULTS = Buffer.from(
'{ "tests": [{ "name": "Test 1", "status": "fail", "message": "Test failed with non-zero exit code." }] }',
).toString('base64')
process.env.INPUT_RUNNERS = 'result1'

const child = cp.spawnSync(node, [ip], options)
const stdout = child.stdout.toString()
expect(stdout).toContain(`❌ Test 1`)
})

test('test errors out', () => {
process.env.RESULT1_RESULTS = Buffer.from(
'{ "tests": [{ "name": "Test 1", "status": "error", "message": "Test failed to execute." }] }',
).toString('base64')
process.env.INPUT_RUNNERS = 'result1'

const child = cp.spawnSync(node, [ip], options)
const stdout = child.stdout.toString()
expect(stdout).toContain(`Error: Test failed to execute.`)
})

test('fails to run if input not in the right format', () => {
process.env.RESULT1_RESULTS = Buffer.from(
'{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }',
).toString('base64')
process.env.RESULT2_RESULTS = Buffer.from(
'{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }',
).toString('base64')
process.env.INPUT_RUNNERS = '[result1,result2]'

const child = cp.spawnSync(node, [ip], options)
const stderr = child.stderr.toString()
expect(stderr).toContain(`The runners input must be a comma-separated list of strings.`)
})

test('test runs with multiple runners', () => {
process.env.RESULT1_RESULTS = Buffer.from(
'{ "tests": [{ "name": "Test 1", "status": "pass", "message": null }] }',
).toString('base64')
process.env.RESULT2_RESULTS = Buffer.from(
'{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }',
).toString('base64')
process.env.INPUT_RUNNERS = 'result1,result2'

const child = cp.spawnSync(node, [ip], options)
const stdout = child.stdout.toString()
console.log(stdout)
expect(stdout).toContain('✅')
})

test('test fails with multiple runners', () => {
process.env.RESULT1_RESULTS = Buffer.from(
'{ "tests": [{ "name": "Test 1", "status": "fail", "message": null }] }',
).toString('base64')
process.env.RESULT2_RESULTS = Buffer.from(
'{ "tests": [{ "name": "Test 2", "status": "pass", "message": null }] }',
).toString('base64')
process.env.INPUT_RUNNERS = 'result1,result2'

const child = cp.spawnSync(node, [ip], options)
const stdout = child.stdout.toString()
console.log(stdout)
expect(stdout).toContain('❌')
})

test('test autograding-output.parseRunnerResults', function () {
process.env.INPUT_RUNNERS = 'result1,result2'

const testResults1 = parseRunnerResults(process.env.INPUT_RUNNERS)
expect(testResults1.length).toBe(2)
expect(testResults1[0].runner).toBe('result1')
expect(testResults1[1].runner).toBe('result2')

process.env.INPUT_RUNNERS = '[result1,result2]'
expect(() => parseRunnerResults(process.env.INPUT_RUNNERS)).toThrow(
'The runners input must be a comma-separated list of strings.',
)
})
Loading