Skip to content

Commit

Permalink
Initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Nov 30, 2017
1 parent 28e82df commit 4bc2d27
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ out
node_modules
npm-debug.log
*.vsix
.vscode-test
18 changes: 14 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
language: node_js
sudo: required
dist: trusty

node_js:
- 6
language: php
php:
- 7.1

env:
- NODE_RELEASE=8.x

before_install:
- sudo rm -rf ~/.nvm - curl -sL "https://deb.nodesource.com/setup_${NODE_RELEASE}" | sudo -E bash -
- sudo apt-get install -y nodejs
- npm install -g yarn

cache:
directories:
Expand All @@ -12,4 +22,4 @@ install:
- yarn install

script:
- npm run build
- npm test
4 changes: 4 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.vscode/**
.vscode-test/**
src/**
out/test/**
test/**
testProject/**
**/*.map
.gitignore
.travis.yml
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ or right mouse context menu `Format Document` or `Format Selection`
| phpfmt.cakephp | `boolean` | Apply CakePHP coding style | false |
| phpfmt.custom_arguments | `string` | provide custom arguments to overwrite default arguments generated by config | "" |


## Contribute

### Running extension
- Open this repository inside VSCode
- Debug sidebar
- `Launch Extension`

### Running tests
```bash
$ npm test
```
12 changes: 12 additions & 0 deletions README.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ or right mouse context menu `Format Document` or `Format Selection`
| Key | Type | Description | Default |
| -------- | ----------- | ----------- | ----------- |
%CONFIG%

## Contribute

### Running extension
- Open this repository inside VSCode
- Debug sidebar
- `Launch Extension`

### Running tests
```bash
$ npm test
```
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
"displayName": "phpfmt - PHP formatter",
"version": "1.0.13",
"description": "Integrates phpfmt into VS Code",
"main": "./out/extension",
"main": "./out/src/extension",
"scripts": {
"vscode:prepublish": "npm run build",
"build": "npm run trash && tsc -p ./",
"prebuild": "npm run generate",
"watch": "tsc -watch -p ./",
"trash": "trash out",
"generate": "node generate",
"postinstall": "node ./node_modules/vscode/bin/install"
"postinstall": "node ./node_modules/vscode/bin/install",
"pretest": "npm run build",
"test": "cross-env CODE_TESTS_WORKSPACE=testProject node ./node_modules/vscode/bin/test"
},
"keywords": [
"phpfmt",
Expand Down Expand Up @@ -135,7 +137,10 @@
},
"devDependencies": {
"@types/detect-indent": "^5.0.0",
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.28",
"cross-env": "^5.1.1",
"mocha": "^4.0.1",
"trash-cli": "^1.4.0",
"typescript": "^2.5.2",
"vscode": "^1.1.0"
Expand Down
34 changes: 34 additions & 0 deletions test/format.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as assert from 'assert';
import * as path from 'path';
import { execSync } from 'child_process';
import {
workspace as Workspace,
window as Window,
commands as Commands
} from 'vscode';

function hasFormat(file: string): Thenable<void> {
const absPath: string = path.join(Workspace.rootPath!, file);

return Workspace.openTextDocument(absPath).then(doc => {
return Window.showTextDocument(doc).then(() =>
Commands.executeCommand('editor.action.formatDocument').then(
() => {
const stdout: Buffer = execSync(
`php ${path.join(
Workspace.rootPath!,
`/../phpf.phar --psr2 --dry-run -o=- ${absPath}`
)}`
);
const phpfmtFormatted: string = stdout.toString();
assert.equal(doc.getText(), phpfmtFormatted);
},
e => console.error(e)
)
);
});
}

suite('Test format', () => {
test('it formats successfully', () => hasFormat('ugly.php'));
});
22 changes: 22 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
//
// This file is providing the test runner to use when running extension tests.
// By default the test runner in use is Mocha based.
//
// You can provide your own test runner if you want to override it by exporting
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
// host can call to run the tests. The test runner is expected to use console.log
// to report the results back to the caller. When the tests are finished, return
// a possible error to the callback or null if none.
var testRunner = require('vscode/lib/testrunner');

// You can directly control Mocha options by uncommenting the following lines
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
testRunner.configure({
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
useColors: true, // colored output from test results
timeout: 10000
});

module.exports = testRunner;
13 changes: 13 additions & 0 deletions testProject/ugly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
class Ugly{
private $ugly;

public function __construct($ugly){
$this->ugly=$ugly;
}

public function getUgly()
{
return $this->ugly;
}
}
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
"module": "commonjs",
"target": "es6",
"outDir": "out",
"rootDir": "src",
"rootDir": ".",
"strict": true,
"noUnusedLocals": true,
"forceConsistentCasingInFileNames": true,
"removeComments": true,
"lib": ["es6"],
"sourceMap": true
},
"include": ["src"],
"exclude": ["node_modules", ".vscode-test"]
"exclude": ["node_modules", ".vscode-test", "testProject"]
}
Loading

0 comments on commit 4bc2d27

Please sign in to comment.