Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Explorer doesn't run mocha tests with fs.readFileSync and possibly more #8

Closed
MystK opened this issue Mar 31, 2015 · 3 comments
Closed

Comments

@MystK
Copy link
Contributor

MystK commented Mar 31, 2015

When I have unit tests that call fs.readFileSync, the test does not show up in Test Explorer, but the code runs fine.

fs.readFile also works fine.

@mousetraps
Copy link
Contributor

Hmm, could you provide some sample code? I can't repro this using the code below.

var assert = require('assert');
var fs = require('fs')

describe('Test Suite 4', function() {
    it('Test 3', function () {
        var txt = fs.readFileSync('hello.txt');
        console.log(txt);
        assert.ok(true, "this should pass");
    })
})

Also just verify that the test framework is marked as "mocha" for every file and try building the project. (Ctrl+Shift+B) We currently discover tests when you modify a file, but you'll have to build when you add new files.

@MystK
Copy link
Contributor Author

MystK commented Apr 2, 2015

The code you provided works, but when the fs.readFileSync is moved out of the test, such as when requiring other files, it doesn't show up in test explorer.

var assert = require('assert');
var fs = require('fs')
var txt = fs.readFileSync('hello.txt');

describe('Test Suite 4', function() {
    it('Test 3', function () {
        assert.ok(true, "this should pass");
    })
})

The above does not work. This is an issue because my test code is something like this.

var app = require('server');
describe('Test Suite', function() {
    it('Test', function () {
    })
})

And the server has a fs.readFileSync.

@mousetraps mousetraps added this to the May milestone May 5, 2015
@mousetraps mousetraps modified the milestones: May, June May 28, 2015
mousetraps added a commit to mousetraps/nodejstools that referenced this issue May 31, 2015
3d72ad8 Renamed IUIThread to UIThreadBase, made public
8cc4608 Merge branch 'master' of https://github.com/Microsoft/PTVS into sync
3c25df2 Removed old files and moved BuildTasks into SharedProject
c1e0840 Remove PTVS environment variable reference
0e7d4c9 Fix issue where project properties was getting error about being unable to resolve a page corresponding to an empty guid.
948bdc9 IUIThread -> abstract class rather than interface because the CLR doesn't take into account assembly names when generating an interfaces GUID, resulting in resolution issues when we reference the interface from multiple assemblies.
308d22d Merge pull request microsoft#281 from zooba/test-copy
800e48e Fixes build issues.
d3cf49d Merge pull request microsoft#270 from zooba/test-fixes
39a776f Merge pull request microsoft#271 from int19h/fix-239
242ec81 Suppress "Find" button in Attach to Process when using the ptvsd port supplier (microsoft#239).
76843c5 Makes refactor rename tests into mock tests and fixes some of them. General test improvements. Updates interface of PythonSuggestedImportAction. Updates VS 2015 build to target .NET 4.6.
2c4dca2 Merge pull request microsoft#266 from zooba/vs2015-images
b907dc0 Clarifies image indexes
4cbff58 Merge pull request microsoft#8 from Microsoft/master
effb8d8 Updates SharedProject to require use of image monikers on VS 2015.
a528e77 Makes copying test files more likely to succeed.
ad96680 Fixes VS 2013 build and tidies usings.
c25e4b9 Fix microsoft#5: Tons of exception spam in the output window
72261c3 Updates HierarchyNode and subclasses to use image monikers.
584f4f3 Fixes missing file.
6a1fdff code review feedback
ffc60c7 Changes running document table to marshal to the UI thread (fixing a bunch of failing tests) Adds multi-select support Decorates tests using mock framework as mock tests Makes command routing more like VS

git-subtree-dir: Common
git-subtree-split: 3d72ad8bd065cfbe56686da5150df1e2fefa221d
@mousetraps mousetraps self-assigned this Jun 10, 2015
@mousetraps
Copy link
Contributor

Just looked into this. The issue appears to be that test discovery is running node from a different path than expected (try running the file from a different directory, and you'll see what I mean).

In general, it's best to do something like path.join(__dirname, filename) instead of just the filename to ensure your working directory is what you're expecting it to be.

Anyways, the fix I'll commit soon will mitigate the confusion by setting the process directory to the project folder, and also print out the working path in the beginning so that it's easier to debug similar issues in the future.

mousetraps added a commit that referenced this issue Jun 17, 2015
Fix #8 - test explorer doesn't run mocha tests with fs.readFileSync and
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants