Skip to content

Commit

Permalink
fix: Disambiguate paths for build (#88)
Browse files Browse the repository at this point in the history
* Disambiguate paths
* Fix tests
  • Loading branch information
diervo committed Mar 8, 2018
1 parent 7023328 commit f5e6290
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 10 additions & 3 deletions packages/best-build/src/__tests__/best-build.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const MOCK_MESSAGER = {
onBenchmarkBuildEnd() {},
logState() {}
};
const projectName = 'test';

function tempDir() {
return fs.mkdtempSync(path.join(os.tmpdir(), TEMP_DIR_PREFIX));
Expand All @@ -22,21 +23,23 @@ describe('buildBenchmark', () => {
path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'),
{
cacheDirectory,
projectName
},
{},
MOCK_MESSAGER,
);

expect(fs.statSync(`${cacheDirectory}/single-file`).isDirectory()).toBe(true);
expect(fs.statSync(`${cacheDirectory}/single-file/single-file.html`).isFile()).toBe(true);
expect(fs.statSync(`${cacheDirectory}/single-file/single-file.js`).isFile()).toBe(true);
expect(fs.statSync(`${cacheDirectory}/${projectName}/single-file`).isDirectory()).toBe(true);
expect(fs.statSync(`${cacheDirectory}/${projectName}/single-file/single-file.html`).isFile()).toBe(true);
expect(fs.statSync(`${cacheDirectory}/${projectName}/single-file/single-file.js`).isFile()).toBe(true);
});

test('build output', async () => {
const { benchmarkName, benchmarkEntry, benchmarkFolder, benchmarkSignature } = await buildBenchmark(
path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'),
{
cacheDirectory: tempDir(),
projectName
},
{},
MOCK_MESSAGER,
Expand All @@ -59,6 +62,8 @@ describe('buildBenchmark', () => {
path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'),
{
cacheDirectory: tempDir(),
projectName

},
{},
messager,
Expand Down Expand Up @@ -92,6 +97,7 @@ describe('buildBenchmark', () => {
path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'),
{
cacheDirectory: tempDir(),
projectName,
plugins: [['build-plugin-opts', PLUGIN_OPTIONS]],
},
{},
Expand Down Expand Up @@ -127,6 +133,7 @@ describe('buildBenchmark', () => {
path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'),
{
cacheDirectory: tempDir(),
projectName,
plugins: ['build-plugin-hooks'],
},
{},
Expand Down
7 changes: 4 additions & 3 deletions packages/best-build/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ function addResolverPlugins({ plugins }) {
}

export async function buildBenchmark(entry, projectConfig, globalConfig, messager) {
messager.onBenchmarkBuildStart(entry, projectConfig.projectName);
const { projectName, cacheDirectory } = projectConfig;
messager.onBenchmarkBuildStart(entry, projectName);

const ext = path.extname(entry);
const benchmarkName = path.basename(entry, ext);
const benchmarkFolder = path.join(projectConfig.cacheDirectory, benchmarkName);
const benchmarkFolder = path.join(cacheDirectory, projectName, benchmarkName);
const benchmarkJSFileName = benchmarkName + ext;
const inputOptions = Object.assign({}, BASE_ROLLUP_INPUT, {
input: entry,
Expand Down Expand Up @@ -67,7 +68,7 @@ export async function buildBenchmark(entry, projectConfig, globalConfig, message

fs.writeFileSync(htmlPath, html, 'utf8');

messager.onBenchmarkBuildEnd(entry, projectConfig.projectName);
messager.onBenchmarkBuildEnd(entry, projectName);

return {
benchmarkName,
Expand Down

0 comments on commit f5e6290

Please sign in to comment.