shelljs/test/pwd.js
Nate Fischer 1a31356343 refactor: use require instead of import
No change to logic. This swaps over tests to use require() since
everything is currently designed for the commonjs module system.
2025-04-07 22:44:24 -07:00

42 lines
797 B
JavaScript

const path = require('path');
const test = require('ava');
const shell = require('..');
const utils = require('./utils/utils');
const cur = process.cwd();
test.beforeEach(t => {
t.context.tmp = utils.getTempDir();
shell.config.resetForTesting();
shell.mkdir(t.context.tmp);
});
test.afterEach.always(t => {
process.chdir(cur);
shell.rm('-rf', t.context.tmp);
});
//
// Valids
//
test('initial directory', t => {
const cwd = shell.pwd();
t.falsy(shell.error());
t.is(cwd.code, 0);
t.falsy(cwd.stderr);
t.is(cwd.toString(), path.resolve('.'));
});
test('after changing directory', t => {
shell.cd(t.context.tmp);
const cwd = shell.pwd();
t.is(cwd.code, 0);
t.falsy(cwd.stderr);
t.falsy(shell.error());
t.is(path.basename(cwd.toString()), t.context.tmp);
});