Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Oct 18, 2021
1 parent 9e7878e commit 4ce1a2f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 67 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -171,7 +171,7 @@ Liftoff.prototype.buildEnvironment = function (opts) {
paths: paths,
});
modulePackage = silentRequire(fileSearch('package.json', [modulePath]));
} catch (e) { }
} catch (e) {}

// if we have a configuration but we failed to find a local module, maybe
// we are developing against ourselves?
Expand Down
139 changes: 73 additions & 66 deletions test/index.js
Expand Up @@ -56,13 +56,11 @@ function cleanup(done) {
}

describe('Liftoff', function () {

this.timeout(5000);

beforeEach(cleanup);

describe('buildEnvironment', function () {

it('should locate local module using cwd if no config is found', function (done) {
var test = new Liftoff({ name: 'chai' });
var cwd = 'explicit/cwd';
Expand Down Expand Up @@ -148,11 +146,11 @@ describe('Liftoff', function () {
var fp = path.resolve(cwd, 'package.json');
expect(stdout).toEqual(
JSON.stringify(require(fp)) +
'\n' +
path.resolve(cwd, 'main.js') +
'\n' +
cwd +
'\n'
'\n' +
path.resolve(cwd, 'main.js') +
'\n' +
cwd +
'\n'
);
done();
}
Expand All @@ -173,7 +171,7 @@ describe('Liftoff', function () {

it(
'should use `index.js` if `main` property in package.json ' +
'does not exist',
'does not exist',
function (done) {
var fixturesDir = path.resolve(__dirname, 'fixtures');
var cwd = path.resolve(fixturesDir, 'developing_yourself/app2');
Expand All @@ -188,11 +186,11 @@ describe('Liftoff', function () {
var fp = './fixtures/developing_yourself/app2/package.json';
expect(stdout).toEqual(
JSON.stringify(require(fp)) +
'\n' +
path.resolve(cwd, 'index.js') +
'\n' +
cwd +
'\n'
'\n' +
path.resolve(cwd, 'index.js') +
'\n' +
cwd +
'\n'
);
done();
}
Expand Down Expand Up @@ -449,9 +447,9 @@ describe('Liftoff', function () {
expect(stderr).toEqual('');
expect(stdout).toEqual(
"saw respawn [ '--lazy' ]\n" +
'preload:success coffeescript/register\n' +
'execute\n' +
''
'preload:success coffeescript/register\n' +
'execute\n' +
''
);
done();
}
Expand Down Expand Up @@ -518,7 +516,9 @@ describe('Liftoff', function () {
});
app.prepare({}, function (env) {
expect(env.configFiles).toEqual({
testconfig: path.resolve('./test/fixtures/configfiles/testconfig.json'),
testconfig: path.resolve(
'./test/fixtures/configfiles/testconfig.json'
),
package: path.resolve('./package.json'),
});
done();
Expand All @@ -529,48 +529,52 @@ describe('Liftoff', function () {
var app = new Liftoff({
name: 'myapp',
configFiles: {
testconfig: [
{ path: '.', extensions: ['.js', '.json'] },
],
testconfig: [{ path: '.', extensions: ['.js', '.json'] }],
},
});
app.prepare({
cwd: 'test/fixtures/configfiles',
}, function (env) {
expect(env.configFiles).toEqual({
testconfig: path.resolve('./test/fixtures/configfiles/testconfig.json'),
});
done();
});
app.prepare(
{
cwd: 'test/fixtures/configfiles',
},
function (env) {
expect(env.configFiles).toEqual({
testconfig: path.resolve(
'./test/fixtures/configfiles/testconfig.json'
),
});
done();
}
);
});

it('should use dirname of configPath if no cwd is specified', function (done) {
var app = new Liftoff({
name: 'myapp',
configFiles: {
testconfig: [
{ path: '.', extensions: ['.js', '.json'] },
],
testconfig: [{ path: '.', extensions: ['.js', '.json'] }],
},
});
app.prepare({
configPath: 'test/fixtures/configfiles/myapp.js',
}, function (env) {
expect(env.configFiles).toEqual({
testconfig: path.resolve('./test/fixtures/configfiles/testconfig.json'),
});
done();
});
app.prepare(
{
configPath: 'test/fixtures/configfiles/myapp.js',
},
function (env) {
expect(env.configFiles).toEqual({
testconfig: path.resolve(
'./test/fixtures/configfiles/testconfig.json'
),
});
done();
}
);
});

it('uses default extensions if not specified (.md)', function (done) {
var app = new Liftoff({
extensions: { '.md': null, '.txt': null },
name: 'myapp',
configFiles: {
README: [
{ path: '.' },
],
README: [{ path: '.' }],
},
});
app.prepare({}, function (env) {
Expand All @@ -586,9 +590,7 @@ describe('Liftoff', function () {
extensions: { '.md': null, '.txt': null },
name: 'myapp',
configFiles: {
README: [
{ path: 'test/fixtures/configfiles' },
],
README: [{ path: 'test/fixtures/configfiles' }],
},
});
app.prepare({}, function (env) {
Expand All @@ -604,9 +606,7 @@ describe('Liftoff', function () {
extensions: { '.md': null, '.txt': null },
name: 'myapp',
configFiles: {
README: [
{ path: '.', extensions: ['.js'] },
],
README: [{ path: '.', extensions: ['.js'] }],
},
});
app.prepare({}, function (env) {
Expand Down Expand Up @@ -644,9 +644,7 @@ describe('Liftoff', function () {
},
name: 'myapp',
configFiles: {
README: [
{ path: '.' },
],
README: [{ path: '.' }],
},
});
app.on('loader:success', function (moduleName, module) {
Expand All @@ -658,11 +656,13 @@ describe('Liftoff', function () {
});

expect(logRequire.length).toEqual(1);
expect(logRequire[0].moduleName)
.toEqual('./test/fixtures/configfiles/require-md');
expect(logRequire[0].moduleName).toEqual(
'./test/fixtures/configfiles/require-md'
);

expect(require(env.configFiles.README))
.toEqual('Load README.md by require-md');
expect(require(env.configFiles.README)).toEqual(
'Load README.md by require-md'
);
done();
});
});
Expand Down Expand Up @@ -690,11 +690,13 @@ describe('Liftoff', function () {
});

expect(logRequire.length).toEqual(1);
expect(logRequire[0].moduleName)
.toEqual('./test/fixtures/configfiles/require-txt');
expect(logRequire[0].moduleName).toEqual(
'./test/fixtures/configfiles/require-txt'
);

expect(require(env.configFiles.README))
.toEqual('Load README.txt by require-txt');
expect(require(env.configFiles.README)).toEqual(
'Load README.txt by require-txt'
);
done();
});
});
Expand All @@ -708,7 +710,9 @@ describe('Liftoff', function () {
README: [
{
path: 'test/fixtures/configfiles',
extensions: { '.txt': './test/fixtures/configfiles/require-non-exist' },
extensions: {
'.txt': './test/fixtures/configfiles/require-non-exist',
},
},
],
},
Expand All @@ -722,8 +726,9 @@ describe('Liftoff', function () {
});

expect(logFailure.length).toEqual(1);
expect(logFailure[0].moduleName)
.toEqual('./test/fixtures/configfiles/require-non-exist');
expect(logFailure[0].moduleName).toEqual(
'./test/fixtures/configfiles/require-non-exist'
);

done();
});
Expand All @@ -739,7 +744,8 @@ describe('Liftoff', function () {
testconfig: [
{
path: 'test/fixtures/configfiles',
extensions: { // ignored
extensions: {
// ignored
'.js': './test/fixtures/configfiles/require-js',
'.json': './test/fixtures/configfiles/require-json',
},
Expand All @@ -755,14 +761,15 @@ describe('Liftoff', function () {
});
app.prepare({}, function (env) {
expect(env.configFiles).toEqual({
testconfig: path.resolve('./test/fixtures/configfiles/testconfig.json'),
testconfig: path.resolve(
'./test/fixtures/configfiles/testconfig.json'
),
});

expect(logRequire.length).toEqual(0);
expect(logFailure.length).toEqual(0);

expect(require(env.configFiles.testconfig))
.toEqual({ aaa: 'AAA' });
expect(require(env.configFiles.testconfig)).toEqual({ aaa: 'AAA' });
done();
});
});
Expand Down

0 comments on commit 4ce1a2f

Please sign in to comment.