test-field-order.jsā¢1.46 kB
#!/usr/bin/env node
/**
* Test Script: Field Order Issue Analysis
* Tests whether JSON.stringify preserves field order in quiz choices
*/
// Test the exact structure from our format-for-composer.js
const correctQuizChoice = {
id: "test-id-123",
correct: true,
text: "<p>Test choice text</p>"
};
// Test structure with fields in wrong order (as saved)
const wrongOrderChoice = {
id: "test-id-123",
text: "<p>Test choice text</p>",
correct: true
};
console.log("=== Field Order Test ===");
console.log("\nCorrect Order (correct before text):");
console.log(JSON.stringify(correctQuizChoice, null, 2));
console.log("\nWrong Order (text before correct):");
console.log(JSON.stringify(wrongOrderChoice, null, 2));
console.log("\n=== Reconstructed Object Test ===");
// Test if reconstruction changes order
const reconstructed = JSON.parse(JSON.stringify(correctQuizChoice));
console.log("Reconstructed from correct order:");
console.log(JSON.stringify(reconstructed, null, 2));
console.log("\n=== Object.keys() Order Test ===");
console.log("Correct choice keys:", Object.keys(correctQuizChoice));
console.log("Wrong choice keys:", Object.keys(wrongOrderChoice));
console.log("\n=== Spread Operator Test ===");
const spreadCorrect = { ...correctQuizChoice };
const spreadWrong = { ...wrongOrderChoice };
console.log("Spread correct:", JSON.stringify(spreadCorrect, null, 2));
console.log("Spread wrong:", JSON.stringify(spreadWrong, null, 2));