Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also await the actual build function, so ember-cli-build.js can export an async builder function. Co-authored-by: Robert Jackson <rjackson@linkedin.com>
- Loading branch information
Showing
5 changed files
with
102 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,59 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const expect = require('../../chai').expect; | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const tmp = require('../../helpers/tmp'); | ||
const os = require('os'); | ||
const findBuildFile = require('../../../lib/utilities/find-build-file'); | ||
|
||
describe('find-build-file', function () { | ||
let tmpPath = 'tmp/find-build-file-test'; | ||
let tmpPath; | ||
let tmpFilename = 'ember-cli-build.js'; | ||
let ROOT = process.cwd(); | ||
|
||
beforeEach(function () { | ||
return tmp.setup(tmpPath).then(function () { | ||
process.chdir(tmpPath); | ||
}); | ||
tmpPath = fs.mkdtempSync(os.tmpdir()); | ||
process.chdir(tmpPath); | ||
}); | ||
|
||
afterEach(function () { | ||
let tmpFilePath = path.resolve(tmpFilename); | ||
delete require.cache[require.resolve(tmpFilePath)]; | ||
|
||
return tmp.teardown(tmpPath); | ||
process.chdir(ROOT); | ||
fs.removeSync(tmpPath); | ||
}); | ||
|
||
it('does not throw an error when the file is valid syntax', function () { | ||
it('does not throw an error when the file is valid commonjs syntax', async function () { | ||
fs.writeFileSync(tmpFilename, "module.exports = function() {return {'a': 'A', 'b': 'B'};}", { encoding: 'utf8' }); | ||
|
||
let result = findBuildFile(); | ||
let result = await findBuildFile(); | ||
expect(result).to.be.a('function'); | ||
expect(result()).to.deep.equal({ a: 'A', b: 'B' }); | ||
}); | ||
|
||
it('throws a SyntaxError if the file contains a syntax mistake', function () { | ||
fs.writeFileSync(tmpFilename, "module.exports = function() {return {'a': 'A' 'b': 'B'};}", { encoding: 'utf8' }); | ||
it('does not throw an error when the file is valid ES module syntax', async function () { | ||
fs.writeFileSync('package.json', JSON.stringify({ type: 'module' }), { encoding: 'utf8' }); | ||
fs.writeFileSync(tmpFilename, "export default function() {return {'a': 'A', 'b': 'B'};}", { encoding: 'utf8' }); | ||
|
||
let result = await findBuildFile(); | ||
expect(result).to.be.a('function'); | ||
expect(result()).to.deep.equal({ a: 'A', b: 'B' }); | ||
}); | ||
|
||
it('throws a SyntaxError if the file contains a syntax mistake', async function () { | ||
fs.writeFileSync(tmpFilename, 'module.exports = ', { encoding: 'utf8' }); | ||
|
||
let error = null; | ||
try { | ||
await findBuildFile(); | ||
} catch (e) { | ||
error = e; | ||
} | ||
|
||
expect(() => { | ||
findBuildFile(); | ||
}).to.throw(SyntaxError, /Could not require '.*':/); | ||
expect(error).to.not.equal(null); | ||
expect(error.constructor).to.equal(SyntaxError); | ||
expect(error.message).to.match(/Could not require 'ember-cli-build.js'/); | ||
}); | ||
|
||
it('does not throw an error when the file is missing', function () { | ||
let result = findBuildFile(tmpPath); | ||
it('does not throw an error when the file is missing', async function () { | ||
let result = await findBuildFile(tmpPath); | ||
expect(result).to.be.null; | ||
}); | ||
}); |