Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Litvinsky committed Jun 6, 2018
1 parent ba13725 commit 64d4bb7
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 54 deletions.
23 changes: 16 additions & 7 deletions .vscode/launch.json
Expand Up @@ -7,22 +7,31 @@
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/**/*.js" ],
"preLaunchTask": "npm: watch"
"outFiles": [
"${workspaceRoot}/out/**/*.js"
],
"preLaunchTask": "npm"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/out/test"
],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
"preLaunchTask": "npm: watch"
"outFiles": [
"${workspaceRoot}/out/test/**/*.js"
],
"preLaunchTask": "npm"
}
]
}
}
44 changes: 26 additions & 18 deletions .vscode/tasks.json
@@ -1,20 +1,28 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
// A task runner that calls a custom npm script that compiles the extension.
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
"version": "0.1.0",
// we want to run npm
"command": "npm",
// the command is a shell script
"isShellCommand": true,
// show the output window only if unrecognized errors occur.
"showOutput": "silent",
// we run the custom script "compile" as defined in package.json
"args": [
"run",
"compile",
"--loglevel",
"silent"
],
// The tsc compiler is started in watching mode
"isBackground": true,
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
"version": "0.0.1",
"publisher": "wix",
"engines": {
"vscode": "^1.18.0"
"vscode": "^1.23.0"
},
"categories": [
"Other"
Expand Down
2 changes: 1 addition & 1 deletion src/parsing.ts
Expand Up @@ -89,4 +89,4 @@ export function transformJSIntoExportExpressions(code) {
} else if (commonJSModuleSystemUsed()) {
return exportAllDeclarationsCommonJS(code);
}
}
}
27 changes: 14 additions & 13 deletions src/test/commonjs.test.ts
@@ -1,28 +1,28 @@

import * as vscode from 'vscode'
import * as sinon from 'sinon';
import {run} from '../extension';
import * as sinon from 'sinon';
import { run } from '../extension';
import * as editorAdapter from '../editor';
import * as directoryPicker from '../directories-picker';
import * as filePicker from '../file-picker';
import * as editor from '../editor';
import * as fileSystem from '../file-system';
import * as chai from 'chai';
import * as sinonChai from 'sinon-chai';
const expect = chai.expect;
const expect = chai.expect;

chai.use(sinonChai);

describe('commonjs support', function() {
describe('commonjs support', function () {
let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
});

beforeEach(() => {
sandbox.stub(directoryPicker,'showDirectoryPicker').returns(Promise.resolve('/folder'));
sandbox.stub(filePicker,'showFilePicker').returns(Promise.resolve('/target.js'));
sandbox.stub(directoryPicker, 'showDirectoryPicker').returns(Promise.resolve('/folder'));
sandbox.stub(filePicker, 'showFilePicker').returns(Promise.resolve('/target.js'));
sandbox.stub(editor, 'activeFileName').returns('source.js');
sandbox.stub(editor, 'activeEditor').returns('67676');
sandbox.stub(editor, 'selectedTextStart').returns({});
Expand All @@ -31,7 +31,8 @@ describe('commonjs support', function() {
sandbox.stub(fileSystem, 'prependTextToFile').returns(Promise.resolve())
sandbox.stub(editor, 'config').returns({
jsModuleSystem: 'commonjs',
jsFilesExtentions: ['js']
jsFilesExtentions: ['js'],
switchToTarget: true
});
sandbox.stub(fileSystem, 'appendTextToFile').returns(Promise.resolve());
sandbox.stub(editor, 'selectedText').returns(`
Expand All @@ -42,36 +43,36 @@ describe('commonjs support', function() {

sandbox.stub(editor, 'openFile');
})

afterEach(function () {
sandbox.restore();
});

it('exports selected declarations from target file', async () => {

it('exports selected declarations from target file', async () => {
await run();

expect(fileSystem.appendTextToFile).to.have.been.calledWith('\n\n\n class Foo {\n\n }\n \n \nmodule.exports = {\n Foo\n};\n \n ', '/target.js');

});

it('removes selected text from the source file', async () => {
it('removes selected text from the source file', async () => {

await run();

expect(fileSystem.removeContentFromFileAtLineAndColumn).to.have.been.called;

});

it('prepends import statement to target with all exported declarations', async () => {
it('prepends import statement to target with all exported declarations', async () => {

await run();

expect(fileSystem.prependTextToFile).to.have.been.calledWith(`const { Foo } = require('./target');\n`);

});

it('should switches to the target file', async () => {
it('should switches to the target file', async () => {

await run();

Expand Down
28 changes: 14 additions & 14 deletions src/test/esm.test.ts
@@ -1,28 +1,28 @@

import * as vscode from 'vscode'
import * as sinon from 'sinon';
import {run} from '../extension';
import * as sinon from 'sinon';
import { run } from '../extension';
import * as editorAdapter from '../editor';
import * as directoryPicker from '../directories-picker';
import * as filePicker from '../file-picker';
import * as editor from '../editor';
import * as fileSystem from '../file-system';
import * as chai from 'chai';
import * as sinonChai from 'sinon-chai';
const expect = chai.expect;
const expect = chai.expect;

chai.use(sinonChai);

describe('esm support', function() {
describe('esm support', function () {
let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
});

beforeEach(() => {
sandbox.stub(directoryPicker,'showDirectoryPicker').returns(Promise.resolve('/folder'));
sandbox.stub(filePicker,'showFilePicker').returns(Promise.resolve('/target.js'));
sandbox.stub(directoryPicker, 'showDirectoryPicker').returns(Promise.resolve('/folder'));
sandbox.stub(filePicker, 'showFilePicker').returns(Promise.resolve('/target.js'));
sandbox.stub(editor, 'activeFileName').returns('source.js');
sandbox.stub(editor, 'activeEditor').returns('67676');
sandbox.stub(editor, 'selectedTextStart').returns({});
Expand All @@ -31,7 +31,8 @@ describe('esm support', function() {
sandbox.stub(fileSystem, 'prependTextToFile').returns(Promise.resolve())
sandbox.stub(editor, 'config').returns({
jsModuleSystem: 'esm',
jsFilesExtentions: ['js']
jsFilesExtentions: ['js'],
switchToTarget: true
});
sandbox.stub(fileSystem, 'appendTextToFile').returns(Promise.resolve());
sandbox.stub(editor, 'selectedText').returns(`
Expand All @@ -42,37 +43,36 @@ describe('esm support', function() {

sandbox.stub(editor, 'openFile');
})

afterEach(function () {
sandbox.restore();
});

it('exports selected declarations from target file', async () => {

it('exports selected declarations from target file', async () => {
await run();

expect(fileSystem.appendTextToFile).to.have.been.calledWith('\nexport class Foo {}\n ', '/target.js');

});

it('removes selected text from the source file', async () => {
it('removes selected text from the source file', async () => {

await run();

expect(fileSystem.removeContentFromFileAtLineAndColumn).to.have.been.called;

});

it('prepends import statement to target with all exported declarations', async () => {
it('prepends import statement to target with all exported declarations', async () => {

await run();

expect(fileSystem.prependTextToFile).to.have.been.calledWith(`import { Foo } from './target';\n`);

});

it('should switches to the target file', async () => {

it('should switches to the target file if defined by the user', async () => {
await run();

expect(editor.openFile).to.have.calledWith('/target.js');
Expand Down

0 comments on commit 64d4bb7

Please sign in to comment.