- Notifications
You must be signed in to change notification settings - Fork 241
Run shared tests from both v3 and v4 of juggler #519
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
coverage | ||
**/node_modules/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "juggler-v3", | ||
"version": "3.0.0", | ||
"dependencies": { | ||
"loopback-datasource-juggler":"3.x", | ||
"should": "^8.4.0" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright IBM Corp. 2019. All Rights Reserved. | ||
// Node module: loopback-connector-postgresql | ||
// This file is licensed under the Artistic License 2.0. | ||
// License text available at https://opensource.org/licenses/Artistic-2.0 | ||
| ||
'use strict'; | ||
| ||
const semver = require('semver'); | ||
const should = require('should'); | ||
const juggler = require('loopback-datasource-juggler'); | ||
const name = require('./package.json').name; | ||
| ||
require('../../test/init'); | ||
| ||
describe(name, function() { | ||
before(function() { | ||
return global.resetDataSourceClass(juggler.DataSource); | ||
}); | ||
| ||
after(function() { | ||
return global.resetDataSourceClass(); | ||
}); | ||
| ||
require('loopback-datasource-juggler/test/common.batch.js'); | ||
require('loopback-datasource-juggler/test/default-scope.test.js'); | ||
require('loopback-datasource-juggler/test/include.test.js'); | ||
| ||
// === Operation hooks ==== // | ||
| ||
const suite = require('loopback-datasource-juggler/test/persistence-hooks.suite.js'); | ||
| ||
const DB_VERSION = process.env.MONGODB_VERSION; | ||
| ||
if (!DB_VERSION) { | ||
console.log('The ENV variable MONGODB_VERSION is not set.' + | ||
' Assuming MongoDB version 2.6 or newer.'); | ||
} | ||
| ||
const DB_HAS_2_6_FEATURES = (!DB_VERSION || | ||
semver.satisfies(DB_VERSION, '>=2.6.0')); | ||
| ||
const customConfig = Object.assign({}, global.config, { | ||
enableOptimisedFindOrCreate: DB_HAS_2_6_FEATURES, | ||
}); | ||
| ||
suite(global.getDataSource(customConfig, juggler.DataSource), should, { | ||
replaceOrCreateReportsNewInstance: DB_HAS_2_6_FEATURES, | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "juggler-v4", | ||
"version": "4.0.0", | ||
"dependencies": { | ||
"loopback-datasource-juggler":"4.x", | ||
"should": "^13.2.3" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright IBM Corp. 2019. All Rights Reserved. | ||
// Node module: loopback-connector-postgresql | ||
// This file is licensed under the Artistic License 2.0. | ||
// License text available at https://opensource.org/licenses/Artistic-2.0 | ||
| ||
'use strict'; | ||
| ||
const semver = require('semver'); | ||
const should = require('should'); | ||
const juggler = require('loopback-datasource-juggler'); | ||
const name = require('./package.json').name; | ||
| ||
require('../../test/init'); | ||
| ||
describe(name, function() { | ||
before(function() { | ||
return global.resetDataSourceClass(juggler.DataSource); | ||
}); | ||
| ||
after(function() { | ||
return global.resetDataSourceClass(); | ||
}); | ||
| ||
require('loopback-datasource-juggler/test/common.batch.js'); | ||
require('loopback-datasource-juggler/test/default-scope.test.js'); | ||
require('loopback-datasource-juggler/test/include.test.js'); | ||
| ||
// === Operation hooks ==== // | ||
| ||
const suite = require('loopback-datasource-juggler/test/persistence-hooks.suite.js'); | ||
| ||
const DB_VERSION = process.env.MONGODB_VERSION; | ||
| ||
if (!DB_VERSION) { | ||
console.log('The ENV variable MONGODB_VERSION is not set.' + | ||
' Assuming MongoDB version 2.6 or newer.'); | ||
} | ||
| ||
const DB_HAS_2_6_FEATURES = (!DB_VERSION || | ||
semver.satisfies(DB_VERSION, '>=2.6.0')); | ||
| ||
const customConfig = Object.assign({}, global.config, { | ||
enableOptimisedFindOrCreate: DB_HAS_2_6_FEATURES, | ||
}); | ||
| ||
suite(global.getDataSource(customConfig, juggler.DataSource), should, { | ||
replaceOrCreateReportsNewInstance: DB_HAS_2_6_FEATURES, | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain why this works with
node_modules/juggler-v3/test.js
? I was expectingdeps/juggler-v3/test.js
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, on Node.js 8+, this works with
deps/juggler-v3/tests.js
too.What happens under the hood: in
package.json
, we specify a dependency onjuggler-v3
as follows:When we run
npm install
, npm adds juggler-v3 tonode_modules
and installs its dependencies.In npm shipped with Node.js 6, juggler-v3 would be copied to
node_modules/juggler-v3
. As a result, there will be nodeps/juggler-v3/node_modules
folder. Callingrequire('loopback-datasource-juggler')
fromdeps/juggler-v3/test.js
would resolve tonode_modules/loopback-datasource-juggler
, which is typically v4 - not what we want!Newer npm versions create a symlink:
With the symlink in place, it does not really matter where we load
juggler-v3/test.js
from.I prefer to keep loading from
node_modules
because I consider it as more correct conceptually.