Skip to content

Commit c9107e0

Browse files
committed
fix: copy top level files into dummy throwaway app for command acceptance tests
Previously, we only copied the dist folder into the throwaway app's copy of the addon. This is problematic because: 1. without a package.json, the addon won't get picked up as a node_module, and 2. if the addon has a processParent hook in it's denali-build.js file, it won't get picked up, and the throwaway app won't compile correctly This changes the logic to copy all the standard publishable parts into the throwaway app's copy of the addon, to better simulate a true installed package. This could become problematic in the future if an addon has some other top level files it needs, but we'll cross that bridge then
1 parent 9592fd3 commit c9107e0

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

lib/test/command-acceptance.ts

+13-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as assert from 'assert';
33
import * as path from 'path';
44
import { spawn, ChildProcess } from 'child_process';
55
import * as tmp from 'tmp';
6+
import { sync as glob } from 'glob';
67
import * as dedent from 'dedent-js';
78
import * as createDebug from 'debug';
89
import symlinkAll from '../utils/symlink-all';
@@ -125,21 +126,18 @@ export default class CommandAcceptanceTest {
125126
fs.mkdirSync(tmpNodeModules);
126127
// We symlink all the node_modules from our addon into the throwaway's node_modules
127128
symlinkAll(path.join(this.projectRoot, 'node_modules'), tmpNodeModules);
128-
// Then we symlink the addon itself over as a dependency of the dummy app
129-
symlinkAll(this.projectRoot, path.join(tmpNodeModules, projectPkg.name), { except: [ 'tmp', 'dist', 'node_modules' ]});
130-
// But we copy (not symlink) the dist folder over, because if the command
131-
// under test compiles the throwaway app, and this addon gets compiled along
132-
// with it, it will try to write the compiled addon into the dist folder.
133-
// But if that folder is symlinked to the real addon dist folder, the writes
134-
// will land in the real dist folder. This will result in concurrency bugs
135-
// if two command acceptance tests are running simultaneously and trying to
136-
// read/write from the same real dist directory.
137-
//
138-
// We check if dist exists first because some addons might be build-only,
139-
// which means they won't create a dist folder on build
140-
if (fs.existsSync(path.join(this.projectRoot, 'dist'))) {
141-
fs.copySync(path.join(this.projectRoot, 'dist'), path.join(tmpNodeModules, projectPkg.name, 'dist'));
142-
}
129+
// Then we copy the addon itself over as a dependency of the dummy app
130+
// (just the publishable parts)
131+
[
132+
'package.json',
133+
'*.md',
134+
'dist/**/*',
135+
'denali-build.js'
136+
].forEach((pattern) => {
137+
glob(pattern, { cwd: this.projectRoot }).forEach((file) => {
138+
fs.copySync(path.join(this.projectRoot, file), path.join(tmpNodeModules, projectPkg.name, file));
139+
});
140+
});
143141
}
144142

145143
/**

0 commit comments

Comments
 (0)