Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Ember.Test.registerWaiter(function(){
iterations++;
// Get all models from the store
// The following should work to get model names:
// var debugAdapter = appInstance.lookup('container-debug-adapter:main');
// debugAdapter.catalogEntriesByType('model');
// but unfortunately it is buggy. Use that once the issue is fixed:
// https://github.com/ember-cli/ember-resolver/issues/120
// Until then:
var modelRegexp = /^[a-zA-Z0-9-_]+\/models\/(.*)$/;
var modelNames = new ModuleRegistry()
.moduleNames()
.filter((name) => modelRegexp.test(name))
.map((name) => modelRegexp.exec(name)[1]);
// Check for models in any pending state. Inspired by:
// https://gist.github.com/rsutphin/73fdad14a24884eee336
var store = appInstance.lookup('service:store');
var pendingStates = ['isSaving','isEmpty', 'isLoading', 'isReloading'];
var allPendingRecords = [];
modelNames.forEach((name) => {
var records = store.peekAll(name);
var pendingRecords = records.filter((r) =>
pendingStates.map((s) => r.get(s)).some((i) => i)
);
allPendingRecords = allPendingRecords.concat(pendingRecords);
});