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 against newest TS versions #28

Merged
merged 8 commits into from
May 17, 2021
18 changes: 0 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"node": ">=10.14"
},
"scripts": {
"pretest": "cd test/fixtures/workspace && npm install && cd ../../..",
"test": "tape test/*.spec.js",
"semantic-release": "semantic-release"
},
Expand Down Expand Up @@ -40,10 +41,7 @@
"husky": "^4.2.5",
"semantic-release": "^17.4.2",
"tape": "^5.0.1",
"typescript": "3.7.5",
"typescript29": "npm:typescript@2.9.1",
"typescript30": "npm:typescript@3.0.1",
"typescript39": "npm:typescript@^3.9.7"
"typescript": "^3.7.5"
},
"dependencies": {
"mock-require": "^3.0.3"
Expand Down
2 changes: 1 addition & 1 deletion src/orderwarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getThisPluginNode(ts, pluginsArrayNode) {
return false;
}
const nameAssignments = getChildren(node, false, ts.SyntaxKind.PropertyAssignment).filter(node => node.name.text === 'name')
return nameAssignments.some(node => node.initializer.kind === ts.SyntaxKind.StringLiteral && /(^|\\|\/)vs-compat-ts-plugin($|\\|\/)/.test(node.initializer.text));
return nameAssignments.some(node => node.initializer.kind === ts.SyntaxKind.StringLiteral && node.initializer.text === 'vs-compat-ts-plugin');
})[0];
}

Expand Down
2 changes: 1 addition & 1 deletion test/TestServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestServer {
const tsServerDir = typescriptServerDir || path.join(__dirname, '..', 'node_modules', 'typescript')
const tsserverPath = path.join(tsServerDir, 'lib', 'tsserver');
const server = fork(tsserverPath, [
'--pluginProbeLocations', path.join(__dirname, '..'),
'--pluginProbeLocations', path.join(tsServerDir, '..'),
'--logFile', logFile,
'--logVerbosity', 'info',
'--disableAutomaticTypingAcquisition'
Expand Down
28 changes: 14 additions & 14 deletions test/cwd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pluginTest('cwd is set before the next plugin init', {
{ name: THIS_PLUGIN.path, workingDirectory: PLUGIN_CWD },
{ name: LOG_CWD_PLUGIN.path }
],
check: (t, { hasMessageBy }) => {
t.ok(hasMessageBy(LOG_CWD_PLUGIN.name, PLUGIN_CWD));
check: (t, { assertHasMessageBy }) => {
assertHasMessageBy(LOG_CWD_PLUGIN.name, PLUGIN_CWD);
}
});

Expand All @@ -22,8 +22,8 @@ pluginTest('cwd is set before the next plugin is loaded', {
{ name: THIS_PLUGIN.path, workingDirectory: PLUGIN_CWD },
{ name: LOG_LOADTIME_CWD_PLUGIN.path }
],
check: (t, { hasMessageBy }) => {
t.ok(hasMessageBy(LOG_LOADTIME_CWD_PLUGIN.name, PLUGIN_CWD));
check: (t, { assertHasMessageBy }) => {
assertHasMessageBy(LOG_LOADTIME_CWD_PLUGIN.name, PLUGIN_CWD);
}
});

Expand All @@ -33,8 +33,8 @@ pluginTest('cwd not changed when null', {
{ name: THIS_PLUGIN.path, workingDirectory: null },
{ name: LOG_CWD_PLUGIN.path }
],
check: (t, { hasMessageBy }) => {
t.ok(hasMessageBy(LOG_CWD_PLUGIN.name, SERVER_CWD));
check: (t, { assertHasMessageBy }) => {
assertHasMessageBy(LOG_CWD_PLUGIN.name, SERVER_CWD);
}
});

Expand All @@ -44,10 +44,10 @@ pluginTest('invalid cwd does not break everything else', {
{ name: THIS_PLUGIN.path, workingDirectory: '/\\not.*valid' },
{ name: LOG_CWD_PLUGIN.path }
],
check: (t, { hasMessageBy }) => {
t.ok(hasMessageBy(THIS_PLUGIN.name, 'Could not set working directory'));
t.ok(hasMessageBy(THIS_PLUGIN.name, 'Meddling completed'));
t.ok(hasMessageBy(LOG_CWD_PLUGIN.name, SERVER_CWD));
check: (t, { assertHasMessageBy }) => {
assertHasMessageBy(THIS_PLUGIN.name, 'Could not set working directory');
assertHasMessageBy(THIS_PLUGIN.name, 'Meddling completed');
assertHasMessageBy(LOG_CWD_PLUGIN.name, SERVER_CWD);
}
});

Expand All @@ -57,8 +57,8 @@ pluginTest('cwd relative to the tsconfig directory', {
{ name: THIS_PLUGIN.path, workingDirectory: RELATIVE_PLUGIN_CWD },
{ name: LOG_CWD_PLUGIN.path }
],
check: (t, { hasMessageBy }) => {
t.ok(hasMessageBy(LOG_CWD_PLUGIN.name, PLUGIN_CWD));
check: (t, { assertHasMessageBy }) => {
assertHasMessageBy(LOG_CWD_PLUGIN.name, PLUGIN_CWD);
}
});

Expand All @@ -68,7 +68,7 @@ pluginTest('cwd can use forward slashes (in all OS)', {
{ name: THIS_PLUGIN.path, workingDirectory: RELATIVE_PLUGIN_CWD.replace(/\\/g, '/') },
{ name: LOG_CWD_PLUGIN.path }
],
check: (t, { hasMessageBy }) => {
t.ok(hasMessageBy(LOG_CWD_PLUGIN.name, PLUGIN_CWD));
check: (t, { assertHasMessageBy }) => {
assertHasMessageBy(LOG_CWD_PLUGIN.name, PLUGIN_CWD);
}
});
16 changes: 8 additions & 8 deletions test/defaults.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ pluginTest('cwd set to . by default', {
plugins: [
{ name: THIS_PLUGIN.path }
],
check: (t, { hasMessageBy }) => {
t.ok(hasMessageBy(THIS_PLUGIN.name, `Updating cwd to ${PROJECT_DIR}`));
check: (t, { assertHasMessageBy }) => {
assertHasMessageBy(THIS_PLUGIN.name, `Updating cwd to ${PROJECT_DIR}`);
}
});

pluginTest('typescript mocked by default', {
plugins: [
{ name: THIS_PLUGIN.path }
],
check: (t, { hasMessageBy }) => {
t.ok(hasMessageBy(THIS_PLUGIN.name, 'Mocking typescript module with the version from tsserver'));
check: (t, { assertHasMessageBy }) => {
assertHasMessageBy(THIS_PLUGIN.name, 'Mocking typescript module with the version from tsserver');
}
});

pluginTest('default to off if onByDefault is set off', {
plugins: [
{ name: THIS_PLUGIN.path, onByDefault: false }
],
check: (t, { hasMessageBy, messagesBy }) => {
check: (t, { assertNotHasMessageBy, messagesBy }) => {
t.notOk(messagesBy(THIS_PLUGIN.name).some(msg => /Updating cwd/.test(msg)));
t.notOk(hasMessageBy(THIS_PLUGIN.name, 'Mocking typescript module with the version from tsserver'));
assertNotHasMessageBy(THIS_PLUGIN.name, 'Mocking typescript module with the version from tsserver');
}
});

pluginTest('default to on if onByDefault is set on', {
plugins: [
{ name: THIS_PLUGIN.path, onByDefault: true }
],
check: (t, { hasMessageBy, messagesBy }) => {
check: (t, { assertHasMessageBy, messagesBy }) => {
t.ok(messagesBy(THIS_PLUGIN.name).some(msg => /Updating cwd/.test(msg)));
t.ok(hasMessageBy(THIS_PLUGIN.name, 'Mocking typescript module with the version from tsserver'));
assertHasMessageBy(THIS_PLUGIN.name, 'Mocking typescript module with the version from tsserver');
}
});
22 changes: 12 additions & 10 deletions test/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@ const path = require('path');
module.exports = {
THIS_PLUGIN: {
name: 'vs-compat-ts-plugin',
path: path.resolve(__dirname, '..', '..', 'index.js'),
namelessPath: '../index.js' // For loading the plugin without having the package name in the path
path: 'vs-compat-ts-plugin',
alias: '@vs-compat-ts-plugin/this'
},
LOG_CWD_PLUGIN: {
name: 'logCwdPlugin', path: path.resolve(__dirname, 'plugins', 'logCwdPlugin.js')
name: 'logCwdPlugin', path: '@vs-compat-ts-plugin/log-cwd-plugin'
},
LOG_LOADTIME_CWD_PLUGIN: {
name: 'logLoadtimeCwdPlugin', path: path.resolve(__dirname, 'plugins', 'logLoadtimeCwdPlugin.js')
name: 'logLoadtimeCwdPlugin', path: '@vs-compat-ts-plugin/log-loadtime-cwd-plugin'
},
LOG_TS_VERSIONS_PLUGIN: {
name: 'logTsVersionsPlugin', path: path.resolve(__dirname, 'plugins', 'logTsVersionsPlugin.js')
name: 'logTsVersionsPlugin', path: '@vs-compat-ts-plugin/log-ts-versions-plugin'
},
LOG_TOP_TS_VERSIONS_PLUGIN: {
name: 'logTopTsVersionsPlugin', path: path.resolve(__dirname, 'plugins', 'logTopTsVersionsPlugin.js')
name: 'logTopTsVersionsPlugin', path: '@vs-compat-ts-plugin/log-top-ts-versions-plugin'
},
BREAK_MOCK_REQUIRE_PLUGIN: {
name: 'breakMockRequirePlugin', path: path.resolve(__dirname, 'plugins', 'breakMockRequirePlugin.js')
name: 'breakMockRequirePlugin', path: '@vs-compat-ts-plugin/break-mock-require-plugin'
},
TS_VERSIONS: {
// Latest and oldest of each major release
'3.9': { version: '3.9.7', path: path.resolve(__dirname, '..', '..', 'node_modules', 'typescript39') },
'3.0': { version: '3.0.1', path: path.resolve(__dirname, '..', '..', 'node_modules', 'typescript30') },
'2.9': { version: '2.9.1', path: path.resolve(__dirname, '..', '..', 'node_modules', 'typescript29') },
'4.2': { version: '4.2.4', path: path.resolve(__dirname, 'workspace', 'node_modules', 'typescript42') },
'4.0': { version: '4.0.7', path: path.resolve(__dirname, 'workspace', 'node_modules', 'typescript40') },
'3.9': { version: '3.9.9', path: path.resolve(__dirname, 'workspace', 'node_modules', 'typescript39') },
'3.0': { version: '3.0.1', path: path.resolve(__dirname, 'workspace', 'node_modules', 'typescript30') },
'2.9': { version: '2.9.1', path: path.resolve(__dirname, 'workspace', 'node_modules', 'typescript29') },
// Can't go back further than 2.8 because tsserver won't work on node 10 (https://github.com/microsoft/TypeScript/commit/1fc3aebc20a13048d6595395f721c6b0078c2c08)
// Can't go back further than 2.9 because the tsconfig warnings stop appearing

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/plugins/break-mock-require-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@vs-compat-ts-plugin/break-mock-require-plugin",
"version": "0.0.0",
"private": true
}
5 changes: 5 additions & 0 deletions test/fixtures/plugins/log-cwd-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@vs-compat-ts-plugin/log-cwd-plugin",
"version": "0.0.0",
"private": true
}
5 changes: 5 additions & 0 deletions test/fixtures/plugins/log-loadtime-cwd-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@vs-compat-ts-plugin/log-loadtime-cwd-plugin",
"version": "0.0.0",
"private": true
}
8 changes: 8 additions & 0 deletions test/fixtures/plugins/log-top-ts-versions-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@vs-compat-ts-plugin/log-top-ts-versions-plugin",
"version": "0.0.0",
"private": true,
"peerDependencies": {
"typescript": "*"
}
}
8 changes: 8 additions & 0 deletions test/fixtures/plugins/log-ts-versions-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@vs-compat-ts-plugin/log-ts-versions-plugin",
"version": "0.0.0",
"private": true,
"peerDependencies": {
"typescript": "*"
}
}
19 changes: 19 additions & 0 deletions test/fixtures/workspace/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@vs-compat-ts-plugin/test",
"version": "0.0.0",
"private": true,
"devDependencies": {
"@vs-compat-ts-plugin/break-mock-require-plugin": "file:../plugins/break-mock-require-plugin",
"@vs-compat-ts-plugin/log-cwd-plugin": "file:../plugins/log-cwd-plugin",
"@vs-compat-ts-plugin/log-loadtime-cwd-plugin": "file:../plugins/log-loadtime-cwd-plugin",
"@vs-compat-ts-plugin/log-top-ts-versions-plugin": "file:../plugins/log-top-ts-versions-plugin",
"@vs-compat-ts-plugin/log-ts-versions-plugin": "file:../plugins/log-ts-versions-plugin",
"@vs-compat-ts-plugin/this": "file:../../..",
"typescript29": "npm:typescript@2.9.1",
"typescript30": "npm:typescript@3.0.1",
"typescript39": "npm:typescript@3.9.9",
"typescript40": "npm:typescript@4.0.7",
"typescript42": "npm:typescript@4.2.4",
"vs-compat-ts-plugin": "file:../../.."
}
}
17 changes: 15 additions & 2 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,22 @@ function pluginTest(testName, { serverCwd, plugins, serverCommands, check }, onl
const logContent = fs.readFileSync(LOG_FILE).toString();
const responses = server.responses;
const messagesBy = getMessagesBy(logContent);
const hasMessageBy = (plugin, msg) => messagesBy(plugin).indexOf(msg) !== -1;
const assertHasMessageBy = (plugin, msg) => {
const hasMessageBy = messagesBy(plugin).indexOf(msg) !== -1;
if(!hasMessageBy) {
t.comment(logContent);
}
t.ok(hasMessageBy);
};
const assertNotHasMessageBy = (plugin, msg) => {
const hasMessageBy = messagesBy(plugin).indexOf(msg) !== -1;
if(hasMessageBy) {
t.comment(logContent);
}
t.notOk(hasMessageBy);
};

check(t, { logContent, responses, messagesBy, hasMessageBy, tsVersion });
check(t, { logContent, responses, messagesBy, assertHasMessageBy, assertNotHasMessageBy, tsVersion });
}
catch(err) {
t.fail('Server failed to run: ' + err.toString());
Expand Down
Loading