-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
application-package: show warning if user set unknown target and expl…
…icitly set it as browser Fixes #7559 Signed-off-by: Maksim Ryzhikov <[email protected]>
- Loading branch information
Showing
3 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
dev-packages/application-package/src/application-package.spec.ts
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 Maksim Ryzhikov and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import * as assert from 'assert'; | ||
import * as temp from 'temp'; | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import { ApplicationPackage } from './application-package'; | ||
import { ApplicationProps } from './application-props'; | ||
import * as sinon from 'sinon'; | ||
|
||
const track = temp.track(); | ||
const sandbox = sinon.createSandbox(); | ||
|
||
describe('application-package', function (): void { | ||
after((): void => { | ||
sandbox.restore(); | ||
track.cleanupSync(); | ||
}); | ||
|
||
it('should print warning if user set unknown target in package.json and use browser as a default value', function (): void { | ||
const warn = sandbox.stub(console, 'warn'); | ||
const root = createProjectWithTarget('foo'); | ||
const applicationPackage = new ApplicationPackage({ projectPath: root }); | ||
assert.equal(applicationPackage.target, ApplicationProps.ApplicationTarget.browser); | ||
assert.equal(warn.called, true); | ||
}); | ||
|
||
it('should set target from package.json', function (): void { | ||
const target = 'electron'; | ||
const root = createProjectWithTarget(target); | ||
const applicationPackage = new ApplicationPackage({ projectPath: root }); | ||
assert.equal(applicationPackage.target, target); | ||
}); | ||
|
||
it('should prefer target from passed options over target from package.json', function (): void { | ||
const pckTarget = 'electron'; | ||
const optTarget = 'browser'; | ||
const root = createProjectWithTarget(pckTarget); | ||
const applicationPackage = new ApplicationPackage({ projectPath: root, appTarget: optTarget }); | ||
assert.equal(applicationPackage.target, optTarget); | ||
}); | ||
|
||
function createProjectWithTarget(target: string): string { | ||
const root = track.mkdirSync('foo-project'); | ||
fs.writeFileSync(path.join(root, 'package.json'), `{"theia": {"target": "${target}"}}`); | ||
return root; | ||
} | ||
}); |
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