Best JavaScript code snippet using storybook-root
test_automigration.js
Source:test_automigration.js
1"use strict";2Cu.import("resource:///modules/MigrationUtils.jsm");3Cu.import("resource://gre/modules/PlacesUtils.jsm");4Cu.import("resource://gre/modules/Preferences.jsm");5Cu.import("resource://testing-common/TestUtils.jsm");6Cu.import("resource://testing-common/PlacesTestUtils.jsm");7let AutoMigrateBackstage = Cu.import("resource:///modules/AutoMigrate.jsm"); /* globals AutoMigrate */8let gShimmedMigratorKeyPicker = null;9let gShimmedMigrator = null;10const kUsecPerMin = 60 * 1000000;11// This is really a proxy on MigrationUtils, but if we specify that directly,12// we get in trouble because the object itself is frozen, and Proxies can't13// return a different value to an object when directly proxying a frozen14// object.15AutoMigrateBackstage.MigrationUtils = new Proxy({}, {16 get(target, name) {17 if (name == "getMigratorKeyForDefaultBrowser" && gShimmedMigratorKeyPicker) {18 return gShimmedMigratorKeyPicker;19 }20 if (name == "getMigrator" && gShimmedMigrator) {21 return function() { return gShimmedMigrator };22 }23 return MigrationUtils[name];24 },25});26do_register_cleanup(function() {27 AutoMigrateBackstage.MigrationUtils = MigrationUtils;28});29/**30 * Test automatically picking a browser to migrate from31 */32add_task(function* checkMigratorPicking() {33 Assert.throws(() => AutoMigrate.pickMigrator("firefox"),34 /Can't automatically migrate from Firefox/,35 "Should throw when explicitly picking Firefox.");36 Assert.throws(() => AutoMigrate.pickMigrator("gobbledygook"),37 /migrator object is not available/,38 "Should throw when passing unknown migrator key");39 gShimmedMigratorKeyPicker = function() {40 return "firefox";41 };42 Assert.throws(() => AutoMigrate.pickMigrator(),43 /Can't automatically migrate from Firefox/,44 "Should throw when implicitly picking Firefox.");45 gShimmedMigratorKeyPicker = function() {46 return "gobbledygook";47 };48 Assert.throws(() => AutoMigrate.pickMigrator(),49 /migrator object is not available/,50 "Should throw when an unknown migrator is the default");51 gShimmedMigratorKeyPicker = function() {52 return "";53 };54 Assert.throws(() => AutoMigrate.pickMigrator(),55 /Could not determine default browser key/,56 "Should throw when an unknown migrator is the default");57});58/**59 * Test automatically picking a profile to migrate from60 */61add_task(function* checkProfilePicking() {62 let fakeMigrator = {sourceProfiles: [{id: "a"}, {id: "b"}]};63 let profB = fakeMigrator.sourceProfiles[1];64 Assert.throws(() => AutoMigrate.pickProfile(fakeMigrator),65 /Don't know how to pick a profile when more/,66 "Should throw when there are multiple profiles.");67 Assert.throws(() => AutoMigrate.pickProfile(fakeMigrator, "c"),68 /Profile specified was not found/,69 "Should throw when the profile supplied doesn't exist.");70 let profileToMigrate = AutoMigrate.pickProfile(fakeMigrator, "b");71 Assert.equal(profileToMigrate, profB, "Should return profile supplied");72 fakeMigrator.sourceProfiles = null;73 Assert.throws(() => AutoMigrate.pickProfile(fakeMigrator, "c"),74 /Profile specified but only a default profile found./,75 "Should throw when the profile supplied doesn't exist.");76 profileToMigrate = AutoMigrate.pickProfile(fakeMigrator);77 Assert.equal(profileToMigrate, null, "Should return default profile when that's the only one.");78 fakeMigrator.sourceProfiles = [];79 Assert.throws(() => AutoMigrate.pickProfile(fakeMigrator),80 /No profile data found/,81 "Should throw when no profile data is present.");82 fakeMigrator.sourceProfiles = [{id: "a"}];83 let profA = fakeMigrator.sourceProfiles[0];84 profileToMigrate = AutoMigrate.pickProfile(fakeMigrator);85 Assert.equal(profileToMigrate, profA, "Should return the only profile if only one is present.");86});87/**88 * Test the complete automatic process including browser and profile selection,89 * and actual migration (which implies startup)90 */91add_task(function* checkIntegration() {92 gShimmedMigrator = {93 get sourceProfiles() {94 do_print("Read sourceProfiles");95 return null;96 },97 getMigrateData(profileToMigrate) {98 this._getMigrateDataArgs = profileToMigrate;99 return Ci.nsIBrowserProfileMigrator.BOOKMARKS;100 },101 migrate(types, startup, profileToMigrate) {102 this._migrateArgs = [types, startup, profileToMigrate];103 },104 };105 gShimmedMigratorKeyPicker = function() {106 return "gobbledygook";107 };108 AutoMigrate.migrate("startup");109 Assert.strictEqual(gShimmedMigrator._getMigrateDataArgs, null,110 "getMigrateData called with 'null' as a profile");111 let {BOOKMARKS, HISTORY, PASSWORDS} = Ci.nsIBrowserProfileMigrator;112 let expectedTypes = BOOKMARKS | HISTORY | PASSWORDS;113 Assert.deepEqual(gShimmedMigrator._migrateArgs, [expectedTypes, "startup", null],114 "migrate called with 'null' as a profile");115});116/**117 * Test the undo preconditions and a no-op undo in the automigrator.118 */119add_task(function* checkUndoPreconditions() {120 gShimmedMigrator = {121 get sourceProfiles() {122 do_print("Read sourceProfiles");123 return null;124 },125 getMigrateData(profileToMigrate) {126 this._getMigrateDataArgs = profileToMigrate;127 return Ci.nsIBrowserProfileMigrator.BOOKMARKS;128 },129 migrate(types, startup, profileToMigrate) {130 this._migrateArgs = [types, startup, profileToMigrate];131 TestUtils.executeSoon(function() {132 Services.obs.notifyObservers(null, "Migration:Ended", undefined);133 });134 },135 };136 gShimmedMigratorKeyPicker = function() {137 return "gobbledygook";138 };139 AutoMigrate.migrate("startup");140 let migrationFinishedPromise = TestUtils.topicObserved("Migration:Ended");141 Assert.strictEqual(gShimmedMigrator._getMigrateDataArgs, null,142 "getMigrateData called with 'null' as a profile");143 let {BOOKMARKS, HISTORY, PASSWORDS} = Ci.nsIBrowserProfileMigrator;144 let expectedTypes = BOOKMARKS | HISTORY | PASSWORDS;145 Assert.deepEqual(gShimmedMigrator._migrateArgs, [expectedTypes, "startup", null],146 "migrate called with 'null' as a profile");147 yield migrationFinishedPromise;148 Assert.ok(Preferences.has("browser.migrate.automigrate.started"),149 "Should have set start time pref");150 Assert.ok(Preferences.has("browser.migrate.automigrate.finished"),151 "Should have set finish time pref");152 Assert.ok(AutoMigrate.canUndo(), "Should be able to undo migration");153 let [beginRange, endRange] = AutoMigrate.getUndoRange();154 let stringRange = `beginRange: ${beginRange}; endRange: ${endRange}`;155 Assert.ok(beginRange <= endRange,156 "Migration should have started before or when it ended " + stringRange);157 yield AutoMigrate.undo();158 Assert.ok(true, "Should be able to finish an undo cycle.");159});160/**161 * Fake a migration and then try to undo it to verify all data gets removed.162 */163add_task(function* checkUndoRemoval() {164 let startTime = "" + Date.now();165 // Insert a login and check that that worked.166 let login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);167 login.init("www.mozilla.org", "http://www.mozilla.org", null, "user", "pass", "userEl", "passEl");168 Services.logins.addLogin(login);169 let storedLogins = Services.logins.findLogins({}, "www.mozilla.org",170 "http://www.mozilla.org", null);171 Assert.equal(storedLogins.length, 1, "Should have 1 login");172 // Insert a bookmark and check that we have exactly 1 bookmark for that URI.173 yield PlacesUtils.bookmarks.insert({174 parentGuid: PlacesUtils.bookmarks.toolbarGuid,175 url: "http://www.example.org/",176 title: "Some example bookmark",177 });178 let bookmark = yield PlacesUtils.bookmarks.fetch({url: "http://www.example.org/"});179 Assert.ok(bookmark, "Should have a bookmark before undo");180 Assert.equal(bookmark.title, "Some example bookmark", "Should have correct bookmark before undo.");181 // Insert 2 history visits - one in the current migration time, one from before.182 let now_uSec = Date.now() * 1000;183 let visitedURI = Services.io.newURI("http://www.example.com/", null, null);184 yield PlacesTestUtils.addVisits([185 {uri: visitedURI, visitDate: now_uSec},186 {uri: visitedURI, visitDate: now_uSec - 100 * kUsecPerMin},187 ]);188 // Verify that both visits get reported.189 let opts = PlacesUtils.history.getNewQueryOptions();190 opts.resultType = opts.RESULTS_AS_VISIT;191 let query = PlacesUtils.history.getNewQuery();192 query.uri = visitedURI;193 let visits = PlacesUtils.history.executeQuery(query, opts);194 visits.root.containerOpen = true;195 Assert.equal(visits.root.childCount, 2, "Should have 2 visits");196 // Clean up:197 visits.root.containerOpen = false;198 // Now set finished pref:199 let endTime = "" + Date.now();200 Preferences.set("browser.migrate.automigrate.started", startTime);201 Preferences.set("browser.migrate.automigrate.finished", endTime);202 // Verify that we can undo, then undo:203 Assert.ok(AutoMigrate.canUndo(), "Should be possible to undo migration");204 yield AutoMigrate.undo();205 // Check that the undo removed the history visits:206 visits = PlacesUtils.history.executeQuery(query, opts);207 visits.root.containerOpen = true;208 Assert.equal(visits.root.childCount, 0, "Should have no more visits");209 visits.root.containerOpen = false;210 // Check that the undo removed the bookmarks:211 bookmark = yield PlacesUtils.bookmarks.fetch({url: "http://www.example.org/"});212 Assert.ok(!bookmark, "Should have no bookmarks after undo");213 // Check that the undo removed the passwords:214 storedLogins = Services.logins.findLogins({}, "www.mozilla.org",215 "http://www.mozilla.org", null);216 Assert.equal(storedLogins.length, 0, "Should have no logins");217 // Finally check prefs got cleared:218 Assert.ok(!Preferences.has("browser.migrate.automigrate.started"),219 "Should no longer have pref for migration start time.");220 Assert.ok(!Preferences.has("browser.migrate.automigrate.finished"),221 "Should no longer have pref for migration finish time.");222});223add_task(function* checkUndoDisablingByBookmarksAndPasswords() {224 let startTime = "" + Date.now();225 Services.prefs.setCharPref("browser.migrate.automigrate.started", startTime);226 // Now set finished pref:227 let endTime = "" + (Date.now() + 1000);228 Services.prefs.setCharPref("browser.migrate.automigrate.finished", endTime);229 AutoMigrate.maybeInitUndoObserver();230 ok(AutoMigrate.canUndo(), "Should be able to undo.");231 // Insert a login and check that that disabled undo.232 let login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);233 login.init("www.mozilla.org", "http://www.mozilla.org", null, "user", "pass", "userEl", "passEl");234 Services.logins.addLogin(login);235 ok(!AutoMigrate.canUndo(), "Should no longer be able to undo.");236 Services.prefs.setCharPref("browser.migrate.automigrate.started", startTime);237 Services.prefs.setCharPref("browser.migrate.automigrate.finished", endTime);238 ok(AutoMigrate.canUndo(), "Should be able to undo.");239 AutoMigrate.maybeInitUndoObserver();240 // Insert a bookmark and check that that disabled undo.241 yield PlacesUtils.bookmarks.insert({242 parentGuid: PlacesUtils.bookmarks.toolbarGuid,243 url: "http://www.example.org/",244 title: "Some example bookmark",245 });246 ok(!AutoMigrate.canUndo(), "Should no longer be able to undo.");247 try {248 Services.logins.removeAllLogins();249 } catch (ex) {}250 yield PlacesUtils.bookmarks.eraseEverything();...
automigrate.js
Source:automigrate.js
1var app = require('../server');2var ds = app.datasources.db;3ds.automigrate('listener');4ds.automigrate('soundcast');5ds.automigrate('episode');6ds.automigrate('listeningSession');7ds.automigrate('transaction');8ds.automigrate('payout');9ds.automigrate('publisher');10ds.automigrate('comment');11ds.automigrate('like');12// ds.automigrate('announcement');13ds.automigrate('category');...
Using AI Code Generation
1var app = require('./server/server');2var ds = app.dataSources.storybookRootDS;3ds.automigrate('User', function(err) {4 if (err) throw err;5 console.log('User model created');6 ds.disconnect();7});8{9 "storybookRootDS": {10 }11}12var loopback = require('loopback');13var boot = require('loopback-boot');14var app = module.exports = loopback();15app.start = function() {16 return app.listen(function() {17 app.emit('started');18 var baseUrl = app.get('url').replace(/\/$/, '');19 console.log('Web server listening at: %s', baseUrl);20 if (app.get('loopback-component-explorer')) {21 var explorerPath = app.get('loopback-component-explorer').mountPath;22 console.log('Browse your REST API at %s%s', baseUrl, explorerPath);23 }24 });25};26boot(app, __dirname, function(err) {27 if (err) throw err;28 if (require.main === module)29 app.start();30});31{32 "_meta": {33 }34}35{36 "options": {37 },38 "properties": {39 "name": {40 }41 },42 "relations": {},43 "methods": {}44}45module.exports = function(app) {
Using AI Code Generation
1const automigrate = require('storybook-root').automigrate;2automigrate().then(function() {3 console.log('migration complete');4}).catch(function(err) {5 console.log('migration failed', err);6});7const automigrate = require('storybook-root').automigrate;8automigrate().then(function() {9 console.log('migration complete');10}).catch(function(err) {11 console.log('migration failed', err);12});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!