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

Users/madhurig/rubytestswithrunner #7369

Merged
merged 4 commits into from
Jun 5, 2018

Conversation

madhurig
Copy link
Contributor

@madhurig madhurig commented Jun 4, 2018

Convert UseRubyVersion tests to use the MockTestRunner. This allows running each test out of proc simulating how tasks are run.

@madhurig madhurig requested a review from lkillgore June 4, 2018 19:57
function reload(): typeof useRubyVersion {
return require('../userubyversion');
}
import fs = require('fs');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, looks to be an unused import.

versionSpec: '= 2.5',
addToPath: false
};
it('finds version in cache in Linux', (done: MochaDone) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be function :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a linter rule for this ;)

process.env['AGENT_VERSION'] = '2.116.0';

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we delete this if it isn't needed, or at least remove the type assertion (<ma.TaskLibAnswers>)?

fs.existsSync = (s) => {
return true;
}
tr.registerMock('fs', fs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like rebinding actual functions on the fs module could cause a confusing bug. Also, if you use a brand-new mock object like you did with tool-lib above, it will tell you right away that you forgot to mock something, where using the actual module will sneak through silently.

}
import fs = require('fs');
import assert = require('assert');
import path = require('path');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import ... require syntax is made for compat with some other JS module loaders, but the ES6-standard import * as path from 'path'; gets treated more strictly and is usually what you want.

For example, TypeScript will treat all of the properties on the module imported with import as as read-only, where with require it will let you reassign them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update, we have both styles in the same file which is not great. Is there a order of imports convention in TS?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From looking at some other tasks it looks like we do Node modules first, then task lib, then 3rd-party modules.

symlinkSync: () => { },
unlinkSync: () => { },
existsSync: () => { return true; },
statSync: () => fs.statSync,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think statSync, writeFileSync, readFileSync must not be used. The mocks here wouldn't work as expected if called -- they're functions that are returning a function object :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They need to be mocked, but should fall through.

@madhurig madhurig merged commit 434e764 into master Jun 5, 2018
@madhurig madhurig deleted the users/madhurig/rubytestswithrunner branch June 5, 2018 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants