Skip to content

Commit

Permalink
Add tests for build command
Browse files Browse the repository at this point in the history
  • Loading branch information
RestingState committed Jan 3, 2024
1 parent 8be03e1 commit 7d4b137
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/src/commands/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { spawnSync } from "node:child_process";
import assert from 'node:assert/strict';
import { mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { chdir } from "node:process";
import Configuration from "../../../lib/configuration.js";
import { existsSync } from "node:fs";

describe("build command", function () {
const rootDirectory = process.cwd();
const pathToPostdoc = resolve(rootDirectory, "bin/postdoc.js");

let tmpDir;
before(async function (done) {
tmpDir = await mkdtemp(join(tmpdir(), ".foo"));
chdir(tmpDir);

spawnSync("node", [pathToPostdoc, "init", "--name", "."]);

const filename = "package.json";
const fileContent = await readFile(filename, "utf8");
const finalContent = fileContent.replace(
/"postdoc":\s*"(.*?)"/g,
`"postdoc": "file:${rootDirectory.replaceAll("\\", "/")}"`
);
await writeFile(filename, finalContent);

spawnSync("npm", ["install"], {shell: true});

await Configuration.initialise({});

done();
});

after(async function (done) {
chdir(rootDirectory);
await rm(tmpDir, { recursive: true });
done();
});

test("check if build command produced folder with builded assets", async function() {
const configuration = Configuration.get();

spawnSync("npm", ["run", "build"], {shell: true});

const outputFolder = configuration.directories.output;

const folderExists = existsSync(outputFolder);

assert.equal(folderExists, true);

const files = await readdir(outputFolder);

assert.equal(files.length > 0, true);
})
})

Check warning on line 57 in test/src/commands/build.js

View workflow job for this annotation

GitHub Actions / Using Node 18 environment

Newline required at end of file but not found

Check warning on line 57 in test/src/commands/build.js

View workflow job for this annotation

GitHub Actions / Using Node 20 environment

Newline required at end of file but not found

0 comments on commit 7d4b137

Please sign in to comment.