Maybe try replacing
if (i == 0) {this.options.values[attributeId] = options[i].id;}
with
if (options.length == 1 ) {this.options.values[attributeId] = options[i].id;}
app/design/frontend/Vendorname/themenamme/Magento_ConfigurableProduct/web/js/configurable.js
just before the end of for loop as explained in this example.
Note: In my case, configurable products are only with selectable dropdown and with these as options
Colors and Sizes, few of the colors have only one option like black. So, the above code works well by pre-selecting if the Colors options have only one option.