Skip to content
Permalink
Browse files

fix(importer): handle the case where productName doesn't exist

`yarn init` and `npm init` don't add a `productName` to `package.json`, and when running import on a project without a `productName`, the config setup would throw an exception, so guard against that. This also implements a very basic import unit test -- maybe we want more, but this at least covers this bug fix and other sanity-check-level issues.
  • Loading branch information
bendemboski authored and malept committed Nov 26, 2017
1 parent a39011b commit 23f191a8b13957e1836dada1d9207d6d925f2377
Showing with 21 additions and 4 deletions.
  1. +4 −2 src/util/forge-config.js
  2. +17 −2 test/slow/api_spec_slow.js
@@ -42,9 +42,11 @@ const proxify = (object, envPrefix) => {
* Sets sensible defaults for the `config.forge` object.
*/
export function setInitialForgeConfig(packageJSON) {
const { name = '', productName = '' } = packageJSON;

/* eslint-disable no-param-reassign */
packageJSON.config.forge.electronWinstallerConfig.name = packageJSON.name.replace(/-/g, '_');
packageJSON.config.forge.windowsStoreConfig.name = packageJSON.productName.replace(/-/g, '');
packageJSON.config.forge.electronWinstallerConfig.name = name.replace(/-/g, '_');
packageJSON.config.forge.windowsStoreConfig.name = productName.replace(/-/g, '');
packageJSON.config.forge.electronPackagerConfig.packageManager = yarnOrNpm();
/* eslint-enable no-param-reassign */
}
@@ -12,12 +12,13 @@ import installDeps from '../../src/util/install-dependencies';
import readPackageJSON from '../../src/util/read-package-json';
import yarnOrNpm from '../../src/util/yarn-or-npm';

const installer = process.argv.find(arg => arg.startsWith('--installer=')) || `--installer=${yarnOrNpm()}`;
const installerArg = process.argv.find(arg => arg.startsWith('--installer=')) || `--installer=${yarnOrNpm()}`;
const installer = installerArg.substr(12);
const forge = proxyquire.noCallThru().load('../../src/api', {
'./install': async () => {},
});

describe(`electron-forge API (with installer=${installer.substr(12)})`, () => {
describe(`electron-forge API (with installer=${installer})`, () => {
let dir;
let dirID = Date.now();

@@ -156,6 +157,20 @@ describe(`electron-forge API (with installer=${installer.substr(12)})`, () => {
});
});

describe('import', () => {
before(async () => {
await ensureTestDirIsNonexistent();
await fs.mkdir(dir);
execSync(`${installer} init -y`, {
cwd: dir,
});
});

it('works', async () => {
await forge.import({ dir });
});
});

describe('after init', () => {
before(async () => {
dir = path.resolve(os.tmpdir(), `electron-forge-test-${dirID}/electron-forge-test`);

0 comments on commit 23f191a

Please sign in to comment.
You can’t perform that action at this time.