HEX
Server: Apache
System: Linux webd004.cluster130.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User: frenchy (106757)
PHP: 7.4.33
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/frenchy/www/french-american.org/current/node_modules/@frctl/fractal/test/core.shell.js
const chai = require('chai');
const expect = chai.expect;
const mock = require('mock-fs');
const path = require('path');
const fs = require('fs');
const sinon = require('sinon');
const spawnStub = sinon.stub();
const proxyquire = require('proxyquire');
const shell = proxyquire('../src/core/shell', {
    child_process: {
        spawn: spawnStub
    }
});

describe('Shell', function() {

    let originalPwd;

    beforeEach(function() {
        originalPwd = process.cwd();
        mock({
            'shelltest': {
                'nested-directory': {},
                'empty-file.txt': ''
            }
        });
    });

    afterEach(function() {
        // Ensure the current working directory is the same as when we started the test suite.
        process.cwd(originalPwd);
        // Reset the filesystem.
        mock.restore();
        // Reset Sinon stubs.
        spawnStub.restore;
    })

    it('can change directory', function() {
        const cwd = process.cwd();
        shell.cd('shelltest');
        expect(process.cwd()).to.equal(`${cwd}${path.sep}shelltest`);
    })

    it('can create a file', function(done) {
        shell.touch('test-file.md');
        fs.stat(path.join(process.cwd(), 'test-file.md'), function(error, stats) {
            if (error) done(error)
            expect(stats.isFile()).to.be.true;
            done();
        })
    });

    it('can execute a child process', function() {
        shell.exec('node', ['-v']);
        const expectation = spawnStub.calledWithExactly('node', ['-v']);
        expect(expectation).to.be.true;
    });
});